<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>HankChan&#39;s Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="你要我写什么描述？">
<meta property="og:type" content="website">
<meta property="og:title" content="HankChan&#39;s Blog">
<meta property="og:url" content="http://hexo.hankchan.cn/page/2/index.html">
<meta property="og:site_name" content="HankChan&#39;s Blog">
<meta property="og:description" content="你要我写什么描述？">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="HankChan&#39;s Blog">
<meta name="twitter:description" content="你要我写什么描述？">
  
    <link rel="alternate" href="/atom.xml" title="HankChan&#39;s Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">HankChan&#39;s Blog</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">生活就像海洋</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://hexo.hankchan.cn"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-e6-88-91-e6-83-b3-e7-9f-a5-e9-81-93-e5-a4-9a-e7-ba-bf-e7-a8-8b-e5-a6-82-e4-bd-95-e5-81-9c-e6-ad-a2" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/08/06/e6-88-91-e6-83-b3-e7-9f-a5-e9-81-93-e5-a4-9a-e7-ba-bf-e7-a8-8b-e5-a6-82-e4-bd-95-e5-81-9c-e6-ad-a2/" class="article-date">
  <time datetime="2016-08-06T12:00:17.000Z" itemprop="datePublished">2016-08-06</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/未分类/">未分类</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/08/06/e6-88-91-e6-83-b3-e7-9f-a5-e9-81-93-e5-a4-9a-e7-ba-bf-e7-a8-8b-e5-a6-82-e4-bd-95-e5-81-9c-e6-ad-a2/">我想知道多线程如何停止</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="记录小小，看的是《Java-Multi-Thread-Programming》"><a href="#记录小小，看的是《Java-Multi-Thread-Programming》" class="headerlink" title="记录小小，看的是《Java Multi-Thread Programming》"></a>记录小小，看的是《Java Multi-Thread Programming》</h3><p>在学习多线程的过程中，很多时候对这个如何停止多线程，或者说让他中断、等待等方面还很浅薄。甚至可以说还没有完全领会多线程设计的原理是怎么一回事。</p>
<p>在学到多线程如何停止的时候，主要看到有几种停止多线程的方式。做个现在这个阶段的我对这方面的学习理解和记录吧！</p>
<h4 id="1-停止不了的线程"><a href="#1-停止不了的线程" class="headerlink" title="1.停止不了的线程"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/%E6%88%91%E6%83%B3%E7%9F%A5%E9%81%93%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A6%82%E4%BD%95%E5%81%9C%E6%AD%A2.md#1停止不了的线程" target="_blank" rel="external"></a>1.停止不了的线程</h4><p>Thread中提供了一个 interrupt() 方法来停止线程，但是实际上它并不像是循环语句中使用break那样，马上中断。本质上，只是在当前的线程中打了一个停止的标识，并不是真的停止线程！</p>
<h4 id="2-判断线程是否是停止状态"><a href="#2-判断线程是否是停止状态" class="headerlink" title="2.判断线程是否是停止状态"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/%E6%88%91%E6%83%B3%E7%9F%A5%E9%81%93%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A6%82%E4%BD%95%E5%81%9C%E6%AD%A2.md#2判断线程是否是停止状态" target="_blank" rel="external"></a>2.判断线程是否是停止状态</h4><p>Thread提供了两个方法： 1. this.interrupted() = 测试当前线程是否已经中断 2. this.isInterrupted() = 测试线程是否已经中断</p>
<p>其源代码声明如下：</p>
<pre><code>public static boolean interrupted() //

public boolean isInterrupted() //
`&lt;/pre&gt;
这一部分太坑爹，不贴我自己的示例代码了！

#### [](https://github.com/hank0chan/blog/blob/master/201608/%E6%88%91%E6%83%B3%E7%9F%A5%E9%81%93%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A6%82%E4%BD%95%E5%81%9C%E6%AD%A2.md#3能停止的线程--异常法优化后可以真正停止的呀)3.能停止的线程--异常法（优化后可以真正停止的呀！）

我们可以利用线程状态的判断来选择跳出循环，达到目的。 选择在for循环中判断this.interrupted()，从而考虑利用break跳出循环是个好办法。如下方代码中的被屏蔽的代码块，就是此方法。

但是该方法存在一个问题，如果代码出现在for循环之外，你会发现就算是执行了interrupt()方法同样不能阻止for循环外的代码的运行！所以我们需要优化呀！
&lt;pre&gt;`public class MyThread extends Thread {

    /**
     * 优化 语句继续运行 的解决方法：
     */
    @SuppressWarnings(&quot;static-access&quot;)
    @Override
    public void run() {
        super.run();
        try {
            for(int i = 0; i &amp;lt; 500000; i++) {
                if(this.interrupted()) {
                    System.out.println(&quot;已经停止状态！准备退出了！&quot;);
                    throw new InterruptedException();
                }
                System.out.println(&quot;执行中, i = &quot; + (i + 1));
            }
            System.out.println(&quot;我是在for循环之后的代码，现在你的this.interrupted是ture所以跳出循环执行了我。。&quot;);
            System.out.println(&quot;注意：===&amp;gt;&amp;gt;如果你看到了我，说明并非执行了interrupt()方法就可以让线程结束&quot;);

        } catch (InterruptedException e) {
            System.out.println(&quot;进到MyThread.java类run方法中的catch中了。。。&quot;);
            e.printStackTrace();
        }
    }

    /*@SuppressWarnings(&quot;static-access&quot;)
    @Override
    public void run() {
        super.run();
        for(int i = 0; i &amp;lt; 500000; i++) {
            if(this.interrupted()) {
                System.out.println(&quot;已经停止状态！准备退出了！&quot;);
                break;
            }
            System.out.println(&quot;执行中, i = &quot; + (i + 1));
        }
        System.out.println(&quot;我是在for循环之后的代码，现在你的this.interrupted是ture所以跳出循环执行了我。。&quot;);
        System.out.println(&quot;注意：===&amp;gt;&amp;gt;如果你看到了我，说明并非执行了interrupt()方法就可以让线程结束&quot;);
    }*/ 
}

@Test
public void testMyThread() {
    try {
        MyThread thread = new MyThread();
        thread.start();
        Thread.sleep(2000);
        thread.interrupt();
    } catch (InterruptedException e) {
        System.out.println(&quot;main &apos;s catch..&quot;);
        e.printStackTrace();
    }
    System.out.println(&quot;end!&quot;);
}
`&lt;/pre&gt;
运行结果如下： [![](https://camo.githubusercontent.com/e612170ae84892c422ad74ee3373a9347db7f239/687474703a2f2f692e696d6775722e636f6d2f516a436f6b69492e706e67)](https://camo.githubusercontent.com/e612170ae84892c422ad74ee3373a9347db7f239/687474703a2f2f692e696d6775722e636f6d2f516a436f6b69492e706e67)

#### [](https://github.com/hank0chan/blog/blob/master/201608/%E6%88%91%E6%83%B3%E7%9F%A5%E9%81%93%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A6%82%E4%BD%95%E5%81%9C%E6%AD%A2.md#4-在沉睡中停止)4\. 在沉睡中停止！！

我对sleep()这个破玩意儿一定很迷糊！！ 来试试用sleep()状态下停止线程的效果吧！
&lt;pre&gt;`public class Mythread1 extends Thread {

    @Override
    public void run() {
        super.run();
        try {
            System.out.println(&quot;run start.....&quot;);
            Thread.sleep(200000);
            System.out.println(&quot;run end.....&quot;);
        } catch (InterruptedException e) {
            System.out.println(&quot;在沉睡中被停止。。进入到catch了！&quot; + this.isInterrupted());
            e.printStackTrace();
        }
    }
}

@Test
public void testMyThread1() {
    try {
        Mythread1 th = new Mythread1();
        th.start();
        Thread.sleep(200);
        th.interrupt();
    } catch (InterruptedException e) {
        System.out.println(&quot;main &apos;s catch...&quot;);
        e.printStackTrace();
    }
    System.out.println(&quot;end!&quot;);
}
`&lt;/pre&gt;
我的理解是：可以看到，在主线程执行200ms后就结束方法，而在子线程中需要200000ms以上的时间，所以在200ms时子线程捕获到一个主线程的中断异常，也跟着中断了线程。

#### [](https://github.com/hank0chan/blog/blob/master/201608/%E6%88%91%E6%83%B3%E7%9F%A5%E9%81%93%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A6%82%E4%BD%95%E5%81%9C%E6%AD%A2.md#5-stop方法弃用)5\. stop()方法，弃用！！

#### [](https://github.com/hank0chan/blog/blob/master/201608/%E6%88%91%E6%83%B3%E7%9F%A5%E9%81%93%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%A6%82%E4%BD%95%E5%81%9C%E6%AD%A2.md#6-使用return停止线程)6\. 使用return停止线程

使用interrupt()方法和return结合同样可以达到效果！ public class MyThread2 extends Thread {
&lt;pre&gt;`    @Override
    public void run() {
        super.run(); //对于这个我还是有点懵
        while(true) {
            if(this.isInterrupted()) {
                System.out.println(&quot;停止了！！&quot;);
                return;
            }
            System.out.println(&quot;timer:&quot; + System.currentTimeMillis());
        }
    }

}

@Test
public void testMyThread2() throws InterruptedException {
    MyThread2 t = new MyThread2();
    t.start();
    Thread.sleep(100);
    t.interrupt();
}
</code></pre>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/08/06/e6-88-91-e6-83-b3-e7-9f-a5-e9-81-93-e5-a4-9a-e7-ba-bf-e7-a8-8b-e5-a6-82-e4-bd-95-e5-81-9c-e6-ad-a2/" data-id="cj359k3x9000kfwv7p3ywizc8" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-e5-af-b9springmvcmybatis-e5-9c-a8-e9-a1-b9-e7-9b-ae-e4-b8-ad-e4-bd-bf-e7-94-a8-e7-9a-84-e5-ad-a6-e4-b9-a0-e6-80-9d-e8-80-83" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/08/05/e5-af-b9springmvcmybatis-e5-9c-a8-e9-a1-b9-e7-9b-ae-e4-b8-ad-e4-bd-bf-e7-94-a8-e7-9a-84-e5-ad-a6-e4-b9-a0-e6-80-9d-e8-80-83/" class="article-date">
  <time datetime="2016-08-05T14:59:40.000Z" itemprop="datePublished">2016-08-05</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Mybatis/">Mybatis</a>►<a class="article-category-link" href="/categories/Mybatis/SpringMVC/">SpringMVC</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/08/05/e5-af-b9springmvcmybatis-e5-9c-a8-e9-a1-b9-e7-9b-ae-e4-b8-ad-e4-bd-bf-e7-94-a8-e7-9a-84-e5-ad-a6-e4-b9-a0-e6-80-9d-e8-80-83/">对SpringMVC+Mybatis在项目中使用的学习思考</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Swift项目：模块化"><a href="#Swift项目：模块化" class="headerlink" title="Swift项目：模块化"></a>Swift项目：模块化</h3><h4 id="1-关于从前端-URL-发送请求到后台调用数据库这块儿"><a href="#1-关于从前端-URL-发送请求到后台调用数据库这块儿" class="headerlink" title="1.关于从前端 URL 发送请求到后台调用数据库这块儿"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#1关于从前端-url-发送请求到后台调用数据库这块儿" target="_blank" rel="external"></a>1.关于从前端 URL 发送请求到后台调用数据库这块儿</h4><p>swift-dao-mybatis 是 mybatis 框架的配置使用模块（且叫做：mybatis模块）。 swift-data-station 和 swift-data-tc 是执行调用数据库相关操作的模块（且叫做：数据模块）。 上述两个数据模块中的 TCRepository.java 和 StationRepository.java 通过继承mybatis 模块下的 MyBatisRepository.java 类执行对数据库的操作。 在 MyBatisRepository.java 类中定义了一个 abstract 修饰的 init 方法和一个 protected 修饰的带参 init方法，由子类继承该 abstract init 方法并在该方法体中调用父类的上述带参 init方法。 该带参 init 方法用于匹配查找相应的 mybatis 的 Mapper 类和 Mpper.xml 文件。 该方法通过 springmvc 配置文件使得该类调用前就被初始化， 就是说，数据模块是通过调用 mybatis 模块共同作为 swift 项目的 DAO 层。</p>
<p>swift-edas-web 和 swift-edas-service 都是web应用，都是用于处理前端的 URL 请求的模块（且叫做：web模块）。 其中主要有相应的子功能模块的APIs接口，并且使用了 SpringMVC 框架，在其 springmvc 配置文件中，定义了每个子功能模块相对应 Service 层的类。 而web模块中自身的 APIs 类就是 SpringMVC 框架中的 Controller 前端控制器类，通过调用配置文件中的 Service 层的业务， 再由 Service 调用 DAO 层从而从数据库中获取前端请求需要的数据。</p>
<p>调用关系图：略。。。</p>
<h4 id="1-网格数据：GridRepository（Radar、Satellite、Nwp）-extends-OTSRepository"><a href="#1-网格数据：GridRepository（Radar、Satellite、Nwp）-extends-OTSRepository" class="headerlink" title="1.网格数据：GridRepository（Radar、Satellite、Nwp） extends OTSRepository"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#1网格数据gridrepositoryradarsatellitenwp-extends-otsrepository" target="_blank" rel="external"></a>1.网格数据：GridRepository（Radar、Satellite、Nwp） extends OTSRepository</h4><h4 id="2-观测数据：TCRepository（Typhoon）-extends-MyBatisRepository"><a href="#2-观测数据：TCRepository（Typhoon）-extends-MyBatisRepository" class="headerlink" title="2.观测数据：TCRepository（Typhoon） extends MyBatisRepository"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#2观测数据tcrepositorytyphoon-extends-mybatisrepository" target="_blank" rel="external"></a>2.观测数据：TCRepository（Typhoon） extends MyBatisRepository</h4><h4 id="3-站点数据：StationRepository（Realtime）-extends-MyBatisRepository"><a href="#3-站点数据：StationRepository（Realtime）-extends-MyBatisRepository" class="headerlink" title="3.站点数据：StationRepository（Realtime） extends MyBatisRepository"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#3站点数据stationrepositoryrealtime-extends-mybatisrepository" target="_blank" rel="external"></a>3.站点数据：StationRepository（Realtime） extends MyBatisRepository</h4><p>对于 GridRepository 的 Service来说，分别有自己的 ProductConfig 和ProductConfigs 。 ProductConfig 是JavaBean。 ProductConfigs Implements SingletonInterface ，重写了 reloadData() 方法，用于从配置文件中读取数据，并被各自的 Service 调用。</p>
<h3 id="关于Mybatis封装使用的部分（个人的理解，有误望指正！）："><a href="#关于Mybatis封装使用的部分（个人的理解，有误望指正！）：" class="headerlink" title="关于Mybatis封装使用的部分（个人的理解，有误望指正！）："></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#关于mybatis封装使用的部分个人的理解有误望指正" target="_blank" rel="external"></a>关于Mybatis封装使用的部分（个人的理解，有误望指正！）：</h3><p>在前面提到， MyBatisRepository 类中的 init() 带参方法会被子类调用，并且传入的 Class&lt;?&gt; resultClass 作为参数，这些 resultClass 实际上就是Mybatis框架中的实体类，在此，每个实体类对应的 Mapper 接口类都在同一个包下。 先通过 init() 方法创建SqlSession ，然后调用 SqlSession 的 getConfiguration 方法获取其 Configuration 属性，再使用 Class.forName(resultClass.getName + “Mapper”); 的方式获得该实体类对应的 Mapper 接口类 mapperClass 。最后调用 Configuration 的 addMapper(mapperClass) 方法将其加入到 Configuration 的 mapperRegistry 属性中，MapperRegistry 中的属性 knownMappers 类型为 HashMap, MapperProxyFactory&gt; 。其中 key 为 Mapper 接口类， value 则是该接口类对应生成的 MapperProxyFactory 封装好的类。 在后期使用 SqlSession 中的方法（如：selectOne() ）去获取相应的Statement 的时候，就会根据方法中的参数（即 StatementId和 SQL 语句的传入参数）到上文提到的该 knownMappers 中根据 key 查找相应的 value 得到 Mapper 代理对象，进而操作数据库。</p>
<h3 id="我的疑问"><a href="#我的疑问" class="headerlink" title="我的疑问"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#我的疑问" target="_blank" rel="external"></a>我的疑问</h3><h4 id="我是否可以理解成为是该-MapperProxyFactory-为其对应的-Mapper接口通过动态代理的方式生成其接口实现类从而调用其-Mapper-接口中的方法以至能够获得其全类名对应的-Statement-从而去操作数据库？"><a href="#我是否可以理解成为是该-MapperProxyFactory-为其对应的-Mapper接口通过动态代理的方式生成其接口实现类从而调用其-Mapper-接口中的方法以至能够获得其全类名对应的-Statement-从而去操作数据库？" class="headerlink" title="我是否可以理解成为是该 MapperProxyFactory 为其对应的 Mapper接口通过动态代理的方式生成其接口实现类从而调用其 Mapper 接口中的方法以至能够获得其全类名对应的 Statement 从而去操作数据库？"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#我是否可以理解成为是该-mapperproxyfactory-为其对应的-mapper接口通过动态代理的方式生成其接口实现类从而调用其-mapper-接口中的方法以至能够获得其全类名对应的-statement-从而去操作数据库" target="_blank" rel="external"></a>我是否可以理解成为是该 MapperProxyFactory 为其对应的 Mapper接口通过动态代理的方式生成其接口实现类从而调用其 Mapper 接口中的方法以至能够获得其全类名对应的 Statement 从而去操作数据库？</h4><h4 id="还是说实质是其实是通过-XxxMapper-xml-中的-Statement-的-namespace-和-StatementId-自动生成接口的实现类从而操作数据库？？"><a href="#还是说实质是其实是通过-XxxMapper-xml-中的-Statement-的-namespace-和-StatementId-自动生成接口的实现类从而操作数据库？？" class="headerlink" title="还是说实质是其实是通过 XxxMapper.xml 中的 Statement 的 namespace 和 StatementId 自动生成接口的实现类从而操作数据库？？"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#还是说实质是其实是通过-xxxmapperxml-中的-statement-的-namespace-和-statementid-自动生成接口的实现类从而操作数据库" target="_blank" rel="external"></a>还是说实质是其实是通过 XxxMapper.xml 中的 Statement 的 namespace 和 StatementId 自动生成接口的实现类从而操作数据库？？</h4><h4 id="按说-mybatis-框架是通过-SqlSession-执行-Executor-利用-Statement-封装的数据与数据库进行交互的，上方两种疑问，私以为是第一种吧？"><a href="#按说-mybatis-框架是通过-SqlSession-执行-Executor-利用-Statement-封装的数据与数据库进行交互的，上方两种疑问，私以为是第一种吧？" class="headerlink" title="按说 mybatis 框架是通过 SqlSession 执行 Executor 利用 Statement 封装的数据与数据库进行交互的，上方两种疑问，私以为是第一种吧？"></a><a href="https://github.com/hank0chan/blog/blob/master/201608/Swift%E6%A8%A1%E5%9D%97%E5%8C%96%E9%A1%B9%E7%9B%AE-%E5%9F%BA%E4%BA%8ESpringMVC%2BMybatis%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%80%9D%E8%80%83%E4%BD%93%E4%BC%9A.md#按说-mybatis-框架是通过-sqlsession-执行-executor-利用-statement-封装的数据与数据库进行交互的上方两种疑问私以为是第一种吧" target="_blank" rel="external"></a>按说 mybatis 框架是通过 SqlSession 执行 Executor 利用 Statement 封装的数据与数据库进行交互的，上方两种疑问，私以为是第一种吧？</h4><p>对mybatis原理有较为清晰认识者，还望留言赐教！</p>
<p>更新———— 经过对 mybatis 源代码的跟踪，发现原来最终的 SqlSession 获取数据库数据的的方法（如：selectOne()）实际上是调用到了 org.apache.ibatis.session.defaults .DefaultSqlSession 类中的一个 selectList() 方法：public List selectList(String statement, Object parameter, RowBounds rowBounds);</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/08/05/e5-af-b9springmvcmybatis-e5-9c-a8-e9-a1-b9-e7-9b-ae-e4-b8-ad-e4-bd-bf-e7-94-a8-e7-9a-84-e5-ad-a6-e4-b9-a0-e6-80-9d-e8-80-83/" data-id="cj359k3wo000ffwv737lo8ywc" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-spring-e6-ba-90-e7-a0-81-e5-af-bc-e5-85-a5-e5-88-b0eclipse" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/08/02/spring-e6-ba-90-e7-a0-81-e5-af-bc-e5-85-a5-e5-88-b0eclipse/" class="article-date">
  <time datetime="2016-08-02T15:45:58.000Z" itemprop="datePublished">2016-08-02</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Eclipse/">Eclipse</a>►<a class="article-category-link" href="/categories/Eclipse/Spring/">Spring</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/08/02/spring-e6-ba-90-e7-a0-81-e5-af-bc-e5-85-a5-e5-88-b0eclipse/">Spring源码导入到Eclipse</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <ol>
<li>下载安装gradle, spring 源码构建加入了gradle支持. gradle下载: <a href="http://www.gradle.org/downloads" target="_blank" rel="external">http://www.gradle.org/downloads</a></li>
<li>下载后设置环境变量: GRADLE_HOME = gradle主目录 , 并在path中加入;%GRADLE_HOME%\bin;</li>
<li>执行 gradle -v 查看gradle是否安装正确。</li>
<li>进入spring项目的本地目录下, 执行命令: gradle eclipse -x :eclipse</li>
<li>显示：BUILD SUCCESSFUL，说明成功。在eclipse中导入存在的项目即可。</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/08/02/spring-e6-ba-90-e7-a0-81-e5-af-bc-e5-85-a5-e5-88-b0eclipse/" data-id="cj359k3zt001ffwv7sg5viw1l" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89slf4j-e5-92-8clogback-e7-9b-b8-e5-85-b3-e7-9a-84-e6-97-a5-e5-bf-97-e7-ae-a1-e7-90-86-e4-bb-8b-e7-bb-8d" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/07/15/ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89slf4j-e5-92-8clogback-e7-9b-b8-e5-85-b3-e7-9a-84-e6-97-a5-e5-bf-97-e7-ae-a1-e7-90-86-e4-bb-8b-e7-bb-8d/" class="article-date">
  <time datetime="2016-07-15T01:57:59.000Z" itemprop="datePublished">2016-07-15</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/日志管理/">日志管理</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/07/15/ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89slf4j-e5-92-8clogback-e7-9b-b8-e5-85-b3-e7-9a-84-e6-97-a5-e5-bf-97-e7-ae-a1-e7-90-86-e4-bb-8b-e7-bb-8d/">（转载学习）slf4j和Logback相关的日志管理介绍</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <div id="csdnEditor" class=" ltr"><br><div class="layout-wrapper-l1"><br><div class="layout-wrapper-l2"><br><div class="layout-wrapper-l3"><br><div class="preview-panel"><br><div class="preview-container"><br><div id="preview-contents"><br><div id="wmd-preview-section-18" class="wmd-preview-section preview-content"><br><br>Logback是由log4j创始人设计的又一个开源日志组件。<br>logback当前分成三个模块：logback-core,logback- classic和logback-access。logback-core是其它两个模块的基础模块。logback-classic是log4j的一个 改良版本。此外logback-classic完整实现SLF4J API使你可以很方便地更换成其它日志系统如log4j或JDK14 Logging。logback-access访问模块与Servlet容器集成提供通过Http来访问日志的功能。 Logback是要与SLF4J结合起来用两个组件的官方网站如下：<br>logback的官方网站：<a href="http://logback.qos.ch/" target="_blank" rel="external">http://logback.qos.ch</a><br>SLF4J的官方网站：<a href="http://www.slf4j.org/" target="_blank" rel="external">http://www.slf4j.org</a><br>本文章用到的组件如下：<br>logback-access-1.0.0.jar<br>logback-classic-1.0.0.jar<br>logback-core-1.0.0.jar<br>slf4j-api-1.6.0.jar<br>如果使用Maven,则依赖如下：<br><br></div><br><div id="wmd-preview-section-19" class="wmd-preview-section preview-content"><br><br>    <span class="hljs-tag">&lt;<span class="hljs-title">dependency</span>&gt;</span>                                        <span class="hljs-tag">&lt;<span class="hljs-title">groupId</span>&gt;</span>ch.qos.logback<span class="hljs-tag">&lt;/<span class="hljs-title">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">artifactId</span>&gt;</span>logback-classic<span class="hljs-tag">&lt;/<span class="hljs-title">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">version</span>&gt;</span>1.1.6<span class="hljs-tag">&lt;/<span class="hljs-title">version</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">dependency</span>&gt;</span><code>&lt;/pre&gt;
    logback的优点：
    1、更快的实现 Logback的内核重写了，在一些关键执行路径上性能提升10倍以上。而且logback不仅性能提升了，初始化内存加载也更小了。
    2、非常充分的测试 Logback经过了几年，数不清小时的测试。Logback的测试完全不同级别的。
    3、Logback-classic非常自然实现了SLF4j Logback-classic实现了 SLF4j。在使用SLF4j中，你都感觉不到logback-classic。而且因为logback-classic非常自然地实现了SLF4J， 所以切换到log4j或者其他日志框架非常容易，只需要提供成另一个jar包就OK，根本不需要去动那些通过SLF4JAPI实现的代码。
    4、非常充分的文档 官方网站有两百多页的文档。
    5、自动重新加载配置文件 当配置文件修改了，Logback-classic能自动重新加载配置文件。扫描过程快且安全，它并不需要另外创建一个扫描线程。这个技术充分保证了应用程序能在JEE环境里面跑得很欢。
    6、Lilith Lilith是log事件的观察者，和log4j的chainsaw类似。而lilith还能处理大数量的log数据 。
    7、谨慎的模式和非常友好的恢复 在谨慎模式下，多个FileAppender实例跑在多个JVM下，能够安全地写到同一个日志文件。RollingFileAppender会有些限制。Logback的FileAppender和它的子类包括RollingFileAppender能够非常友好地从I/O异常中恢复。
    8、配置文件可以处理不同的情况 开发人员经常需要判断不同的Logback配置文件在不同的环境下（开发，测试，生产）。而这些配置文件仅仅只有一些很小的不同，可以通过,和来实现，这样一个配置文件就可以适应多个环境。
    9、Filters（过滤器） 有些时候，需要诊断一个问题，需要打出日志。在log4j，只有降低日志级别，不过这样会打出大量的日志，会影响应用性能。在Logback，你可以继续保持那个日志级别而除掉某种特殊情况，如alice这个用户登录，她的日志将打在DEBUG级别而其他用户可以继续打在WARN级别。要实现这个功能只需加4行XML配置。可以参考MDCFIlter 。
    10、SiftingAppender（一个非常多功能的Appender） 它可以用来分割日志文件根据任何一个给定的运行参数。如，SiftingAppender能够区别日志事件跟进用户的Session，然后每个用户会有一个日志文件。
    11、自动压缩已经打出来的log RollingFileAppender在产生新文件的时候，会自动压缩已经打出来的日志文件。压缩是个异步过程，所以甚至对于大的日志文件，在压缩过程中应用不会受任何影响。
    12、堆栈树带有包版本 Logback在打出堆栈树日志时，会带上包的数据。
    13、自动去除旧的日志文件 通过设置TimeBasedRollingPolicy或者SizeAndTimeBasedFNATP的maxHistory属性，你可以控制已经产生日志文件的最大数量。如果设置maxHistory 12，那那些log文件超过12个月的都会被自动移除。

    Logback的配置介绍
    1、Logger、appender及layout
    Logger作为日志的记录器，把它关联到应用的对应的context上后，主要用于存放日志对象，也可以定义日志类型、级别。
    Appender主要用于指定日志输出的目的地，目的地可以是控制台、文件、远程套接字服务器、 MySQL、 PostreSQL、 Oracle和其他数据库、JMS和远程UNIX Syslog守护进程等。
    Layout 负责把事件转换成字符串，格式化的日志信息的输出。
    2、logger context
    各个logger 都被关联到一个 LoggerContext，LoggerContext负责制造logger，也负责以树结构排列各 logger。其他所有logger也通过org.slf4j.LoggerFactory 类的静态方法getLogger取得。 getLogger方法以 logger 名称为参数。用同一名字调用LoggerFactory.getLogger 方法所得到的永远都是同一个logger对象的引用。
    3、有效级别及级别的继承
    Logger 可以被分配级别。级别包括：TRACE、DEBUG、INFO、WARN 和 ERROR，定义于 ch.qos.logback.classic.Level类。如果logger没有被分配级别，那么它将从有被分配级别的最近的祖先那里继承级别。root logger 默认级别是 DEBUG。
    4、打印方法与基本的选择规则
    打印方法决定记录请求的级别。例如，如果 L 是一个 logger 实例，那么，语句 L.info(“..”)是一条级别为 INFO 的记录语句。记录请求的级别在高于或等于其 logger 的有效级别时被称为被启用，否则，称为被禁用。记录请求级别为 p，其 logger的有效级别为 q，只有则当p&amp;gt;=q时，该请求才会被执行。
    该规则是 logback 的核心。级别排序为： TRACE &amp;lt; DEBUG &amp;lt; INFO &amp;lt; WARN &amp;lt; ERROR。

    Logback的默认配置
    如果配置文件 logback-test.xml 和 logback.xml 都不存在，那么 logback 默认地会调用BasicConfigurator ，创建一个最小化配置。最小化配置由一个关联到根 logger 的ConsoleAppender 组成。输出用模式为%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n的 PatternLayoutEncoder 进行格式化。root logger 默认级别是 DEBUG。
    1、Logback的配置文件
    Logback 配置文件的语法非常灵活。正因为灵活，所以无法用 DTD 或 XML schema 进行定义。尽管如此，可以这样描述配置文件的基本结构：以开头，后面有零个或多个元素，有零个或多个元素，有最多一个元素。
    2、Logback默认配置的步骤
    (1). 尝试在 classpath 下查找文件 logback-test.xml；
    (2). 如果文件不存在，则查找文件 logback.xml；
    (3). 如果两个文件都不存在，logback 用 BasicConfigurator 自动对自己进行配置，这会导致记录输出到控制台。
    3、Logback.xml 文件

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-20&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-pi">&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">configuration</span> <span class="hljs-attribute">debug</span>=<span class="hljs-value">“false”</span>&gt;</span><br>        <span class="hljs-comment">&lt;!–定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径–&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“LOG_HOME”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“/home”</span> /&gt;</span><br>        <span class="hljs-comment">&lt;!– 控制台输出 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">appender</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“STDOUT”</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.core.ConsoleAppender”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">encoder</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.classic.encoder.PatternLayoutEncoder”</span>&gt;</span><br>                 <span class="hljs-comment">&lt;!–格式化输出,%d:日期;%thread:线程名;%-5level：级别,从左显示5个字符宽度;%msg:日志消息;%n:换行符–&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">pattern</span>&gt;</span>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-title">pattern</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">encoder</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">appender</span>&gt;</span><br>        <span class="hljs-comment">&lt;!– 按照每天生成日志文件 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">appender</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“FILE”</span>  <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.core.rolling.RollingFileAppender”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">rollingPolicy</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.core.rolling.TimeBasedRollingPolicy”</span>&gt;</span><br>                <span class="hljs-comment">&lt;!–日志文件输出的文件名–&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">FileNamePattern</span>&gt;</span>${LOG_HOME}/TestWeb.log.%d{yyyy-MM-dd}.log<span class="hljs-tag">&lt;/<span class="hljs-title">FileNamePattern</span>&gt;</span><br>                <span class="hljs-comment">&lt;!–日志文件保留天数–&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">MaxHistory</span>&gt;</span>30<span class="hljs-tag">&lt;/<span class="hljs-title">MaxHistory</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">rollingPolicy</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">encoder</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.classic.encoder.PatternLayoutEncoder”</span>&gt;</span><br>                <span class="hljs-comment">&lt;!–格式化输出,%d:日期;%thread:线程名;%-5level：级别,从左显示5个字符宽度;%msg:日志消息;%n:换行符–&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">pattern</span>&gt;</span>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-title">pattern</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">encoder</span>&gt;</span><br>            <span class="hljs-comment">&lt;!–日志文件最大的大小–&gt;</span><br>           <span class="hljs-tag">&lt;<span class="hljs-title">triggeringPolicy</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy”</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-title">MaxFileSize</span>&gt;</span>10MB<span class="hljs-tag">&lt;/<span class="hljs-title">MaxFileSize</span>&gt;</span><br>           <span class="hljs-tag">&lt;/<span class="hljs-title">triggeringPolicy</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">appender</span>&gt;</span><br>       <span class="hljs-comment">&lt;!– show parameters for hibernate sql 专为 Hibernate 定制 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“org.hibernate.type.descriptor.sql.BasicBinder”</span>  <span class="hljs-attribute">level</span>=<span class="hljs-value">“TRACE”</span> /&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“org.hibernate.type.descriptor.sql.BasicExtractor”</span>  <span class="hljs-attribute">level</span>=<span class="hljs-value">“DEBUG”</span> /&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“org.hibernate.SQL”</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“DEBUG”</span> /&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“org.hibernate.engine.QueryParameters”</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“DEBUG”</span> /&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“org.hibernate.engine.query.HQLQueryPlan”</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“DEBUG”</span> /&gt;</span><br><br>        <span class="hljs-comment">&lt;!–myibatis log configure–&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“com.apache.ibatis”</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“TRACE”</span>/&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“java.sql.Connection”</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“DEBUG”</span>/&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“java.sql.Statement”</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“DEBUG”</span>/&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">logger</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“java.sql.PreparedStatement”</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“DEBUG”</span>/&gt;</span><br><br>        <span class="hljs-comment">&lt;!– 日志输出级别 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">root</span> <span class="hljs-attribute">level</span>=<span class="hljs-value">“INFO”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">appender-ref</span> <span class="hljs-attribute">ref</span>=<span class="hljs-value">“STDOUT”</span> /&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">appender-ref</span> <span class="hljs-attribute">ref</span>=<span class="hljs-value">“FILE”</span> /&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">root</span>&gt;</span><br>         <span class="hljs-comment">&lt;!–日志异步到数据库 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">appender</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“DB”</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.classic.db.DBAppender”</span>&gt;</span><br>            <span class="hljs-comment">&lt;!–日志异步到数据库 –&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">connectionSource</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“ch.qos.logback.core.db.DriverManagerConnectionSource”</span>&gt;</span><br>               <span class="hljs-comment">&lt;!–连接池 –&gt;</span><br>               <span class="hljs-tag">&lt;<span class="hljs-title">dataSource</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“com.mchange.v2.c3p0.ComboPooledDataSource”</span>&gt;</span><br>                  <span class="hljs-tag">&lt;<span class="hljs-title">driverClass</span>&gt;</span>com.mysql.jdbc.Driver<span class="hljs-tag">&lt;/<span class="hljs-title">driverClass</span>&gt;</span><br>                  <span class="hljs-tag">&lt;<span class="hljs-title">url</span>&gt;</span>jdbc:mysql://127.0.0.1:3306/databaseName<span class="hljs-tag">&lt;/<span class="hljs-title">url</span>&gt;</span><br>                  <span class="hljs-tag">&lt;<span class="hljs-title">user</span>&gt;</span>root<span class="hljs-tag">&lt;/<span class="hljs-title">user</span>&gt;</span><br>                  <span class="hljs-tag">&lt;<span class="hljs-title">password</span>&gt;</span>root<span class="hljs-tag">&lt;/<span class="hljs-title">password</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-title">dataSource</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">connectionSource</span>&gt;</span><br>      <span class="hljs-tag">&lt;/<span class="hljs-title">appender</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">configuration</span>&gt;</span><br><br></div><br><div id="wmd-preview-section-footnotes" class="preview-content"></div><br></div><br></div><br></div><br></div><br><div class="extension-preview-buttons animate closed"><br><div class="btn-group drag-me dropup" title="这里可以拖拽"></div><br><div class="btn-group dropup"></div><br><div class="btn-group dropup"></div><br><div class="btn-group dropup"><button class="btn btn-success dropdown-toggle stat-button" title="统计信息" data-toggle="dropdown"> <span class="value">5522</span></button></div><br></div><br></div><br></div><br></div>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/07/15/ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89slf4j-e5-92-8clogback-e7-9b-b8-e5-85-b3-e7-9a-84-e6-97-a5-e5-bf-97-e7-ae-a1-e7-90-86-e4-bb-8b-e7-bb-8d/" data-id="cj359k3z60016fwv7to23jpuz" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-e9-83-a8-e5-88-86linux-e5-ad-a6-e4-b9-a0-e9-81-87-e5-88-b0-e7-9a-84-e9-97-ae-e9-a2-98-e5-8f-8a-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95-ef-bc-88-e6-9c-89-e7-a9-ba-e4-bc-9a-e6-9b-b4-e6-96-b0-e3-80-82" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/06/19/e9-83-a8-e5-88-86linux-e5-ad-a6-e4-b9-a0-e9-81-87-e5-88-b0-e7-9a-84-e9-97-ae-e9-a2-98-e5-8f-8a-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95-ef-bc-88-e6-9c-89-e7-a9-ba-e4-bc-9a-e6-9b-b4-e6-96-b0-e3-80-82/" class="article-date">
  <time datetime="2016-06-18T16:39:23.000Z" itemprop="datePublished">2016-06-19</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Linux/">Linux</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/06/19/e9-83-a8-e5-88-86linux-e5-ad-a6-e4-b9-a0-e9-81-87-e5-88-b0-e7-9a-84-e9-97-ae-e9-a2-98-e5-8f-8a-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95-ef-bc-88-e6-9c-89-e7-a9-ba-e4-bc-9a-e6-9b-b4-e6-96-b0-e3-80-82/">部分Linux学习遇到的问题及解决方法（有空会更新。。。。。的）</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <div id="wmd-preview-section-19" class="wmd-preview-section preview-content"><br><br>### 说明：使用的是VMware虚拟机上的CentOS 6.7的Linux系统，用的是命令行界面。本文主要是汇总记录一些学习过程中遇到的部分问题和解决方法，就当做是Linux学习笔记吧！（Q即问题，A即解决方法）<br><br></div><br><div id="wmd-preview-section-20" class="wmd-preview-section preview-content"><br><br>#### Q：”man”命令不可用，提示：-bash:man:command not found<br><br>A： 没有安装man手册，使用命令安装:<br><br></div><br><div id="wmd-preview-section-21" class="wmd-preview-section preview-content"><br><br>    yum <span class="hljs-keyword">install</span> -y man*<code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-22&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### Q：将 /dev/cdrom 挂载到 /mnt 目录下的一个新建文件 /cdr 中的演示

    A：使用 “mount” 命令，参数为被挂载设备和挂载目标文件夹，如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-23&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>mount /dev/cdrom /mnt/cdr<code>&lt;/pre&gt;
    解挂的命令为 “umount” ，其参数为被挂载设备或者挂载目标文件夹之一即可。解挂时如果显示”device is busy” 可以使用cd .. 退出当前挂载目录，再执行解挂命令即可。

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-24&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### Q：使用 “cat” 命令查看文件

    A：参数直接为文件名即可查看文件，如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-25&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>cat HelloWorld<span class="hljs-preprocessor">.java</span><code>&lt;/pre&gt;
    同时，还可以使用 “tail”， “nl”， “head” 等命令，分别查看后几行、显示行号查看文件、查看头几行等。其他参数不做赘述，有需要查Google！

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-26&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### Q：系统用户账号的管理

    A：新增用户使用 “useradd” 命令，删除用户使用 “userdel” 命令，密码管理使用 “passwd” 命令，具体如下：
    新建用户sam，指定其主目录为 /usr/sam:

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-27&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>useradd <span class="hljs-attribute">-d</span> /usr/sam <span class="hljs-attribute">-m</span> sam<code>&lt;/pre&gt;
    删除用户sam，选项 “-r” 指同时删除其主目录:

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-28&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>userdel <span class="hljs-attribute">-r</span> sam<code>&lt;/pre&gt;
    为用户管理密码，包括设置、修改密码；在root权限下，passwd可以使用选项 “-l” 或者 “-u” 分别执行锁定用户和解锁用户操作，选项 “-d” 则是将用户口令置为空：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-29&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>passwd <span class="hljs-operator">-l</span> sam<code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-30&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>passwd <span class="hljs-attribute">-u</span> sam<code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-31&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>passwd <span class="hljs-operator">-d</span> sam<code>&lt;/pre&gt;
    如果是在用户权限下，直接输入 “passwd” 命令可以用户修改密码。

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-32&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### Q：运行Shell脚本的两种方法

    打开文本编辑器(可以使用vi/vim命令来创建文件)，新建一个文件test.sh，扩展名为sh（sh代表shell），扩展名并不影响脚本执行，见名知意就好，如果你用php写shell 脚本，扩展名就用php好了。
    输入一些代码，实例：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-33&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-shebang">#!/bin/bash</span><br>    <span class="hljs-built_in">echo</span> <span class="hljs-string">“Hello World !”</span><code>&lt;/pre&gt;
    A：
    1\. 作为可执行程序
    将上面的代码保存为test.sh，并且cd到相应目录：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-34&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code> chmod +<span class="hljs-built_in">x</span> ./test<span class="hljs-preprocessor">.sh</span> <span class="hljs-preprocessor">#使脚本具有执行权限</span><br>     ./test<span class="hljs-preprocessor">.sh</span> <span class="hljs-preprocessor">#执行脚本</span><code>&lt;/pre&gt;
    注意，一定要写成./test.sh，而不是test.sh，运行其它二进制的程序也一样，直接写test.sh，linux系统会去PATH里寻找有没有叫test.sh的，而只有/bin, /sbin, /usr/bin，/usr/sbin等在PATH里，你的当前目录通常不在PATH里，所以写成test.sh是会找不到命令的，要用./test.sh告诉系统说，就在当前目录找。
    2\. 作为解释器参数
    这种运行方法是直接运行解释器，其参数就是shell脚本的文件名，如：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-35&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>/bin/sh test<span class="hljs-preprocessor">.sh</span><br>    /bin/php test<span class="hljs-preprocessor">.php</span><br><br>这种方式运行的脚本，不需要在第一行指定解释器信息，写了也没作用。<br><br></div>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/06/19/e9-83-a8-e5-88-86linux-e5-ad-a6-e4-b9-a0-e9-81-87-e5-88-b0-e7-9a-84-e9-97-ae-e9-a2-98-e5-8f-8a-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95-ef-bc-88-e6-9c-89-e7-a9-ba-e4-bc-9a-e6-9b-b4-e6-96-b0-e3-80-82/" data-id="cj359k3yp000zfwv796yk6vea" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89git-e5-9f-ba-e7-a1-80-e8-8e-b7-e5-8f-96-git-e4-bb-93-e5-ba-93" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/05/10/ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89git-e5-9f-ba-e7-a1-80-e8-8e-b7-e5-8f-96-git-e4-bb-93-e5-ba-93/" class="article-date">
  <time datetime="2016-05-10T06:51:47.000Z" itemprop="datePublished">2016-05-10</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Git/">Git</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/05/10/ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89git-e5-9f-ba-e7-a1-80-e8-8e-b7-e5-8f-96-git-e4-bb-93-e5-ba-93/">（转载学习）Git 基础 - 获取 Git 仓库</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="2-1-Git-基础-获取-Git-仓库"><a href="#2-1-Git-基础-获取-Git-仓库" class="headerlink" title="2.1 Git 基础 - 获取 Git 仓库"></a>2.1 Git 基础 - 获取 Git 仓库</h1><div><a id="_git_basics_chapter" target="_blank"></a>说明出处：<a href="https://git-scm.com/book/zh/v2/Git-基础-获取-Git-仓库" target="_blank" rel="external">https://git-scm.com/book/zh/v2/Git-基础-获取-Git-仓库</a><br><br>假如你只能阅读一章来学习 Git，本章就是你的不二选择。 本章内容涵盖你在使用 Git 完成各种工作中将要使用的各种基本命令。 在学习完本章之后，你应该能够配置并初始化一个仓库（repository）、开始或停止跟踪（track）文件、暂存（stage）或提交（commit)更改。 本章也将向你演示如何配置 Git 来忽略指定的文件和文件模式、如何迅速而简单地撤销错误操作、如何浏览你的项目的历史版本以及不同提交（commits）间的差异、如何向你的远程仓库推送（push）以及如何从你的远程仓库拉取（pull）文件。<br><br><a id="_getting_a_repo" target="_blank"></a><br><br>## 获取 Git 仓库<br><br>有两种取得 Git 项目仓库的方法。 第一种是在现有项目或目录下导入所有文件到 Git 中； 第二种是从一个服务器克隆一个现有的 Git 仓库。<br><br>### <a href="https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E8%8E%B7%E5%8F%96-Git-%E4%BB%93%E5%BA%93#在现有目录中初始化仓库" target="_blank" rel="external">在现有目录中初始化仓库</a><br><br>如果你打算使用 Git 来对现有的项目进行管理，你只需要进入该项目目录并输入：<br><br>    $<code>git init&lt;/pre&gt;
    该命令将创建一个名为</code>.git<code>的子目录，这个子目录含有你初始化的 Git 仓库中所有的必须文件，这些文件是 Git 仓库的骨干。 但是，在这个时候，我们仅仅是做了一个初始化的操作，你的项目里的文件还没有被跟踪。 (参见 [Git 内部原理](https://git-scm.com/book/zh/v2/1-git-internals/_git_internals) 来了解更多关于到底</code>.git<code>文件夹中包含了哪些文件的信息。)&lt;a id=&quot;id-xoc0sksviqiv&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;

    如果你是在一个已经存在文件的文件夹（而不是空文件夹）中初始化 Git 仓库来进行版本控制的话，你应该开始跟踪这些文件并提交。 你可通过</code>git add<code>命令来实现对指定文件的跟踪，然后执行</code>git commit<code>提交：
    &lt;pre&gt;</code>$<code>git add *.c</code>$<code>git add LICENSE</code>$<code>git commit -m</code>‘initial project version’<br><br>稍后我们再逐一解释每一条指令的意思。 现在，你已经得到了一个实际维护（或者说是跟踪）着若干个文件的 Git 仓库。<br><br>### <a href="https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E8%8E%B7%E5%8F%96-Git-%E4%BB%93%E5%BA%93#克隆现有的仓库" target="_blank" rel="external">克隆现有的仓库</a><br><br>如果你想获得一份已经存在了的 Git 仓库的拷贝，比如说，你想为某个开源项目贡献自己的一份力，这时就要用到 <code>git clone</code> 命令。 如果你对其它的 VCS 系统（比如说Subversion）很熟悉，请留心一下你所使用的命令是”clone”而不是”checkout”。 这是 Git 区别于其它版本控制系统的一个重要特性，Git 克隆的是该 Git 仓库服务器上的几乎所有数据，而不是仅仅复制完成你的工作所需要文件。 当你执行 <code>git clone</code> 命令的时候，默认配置下远程 Git 仓库中的每一个文件的每一个版本都将被拉取下来。 事实上，如果你的服务器的磁盘坏掉了，你通常可以使用任何一个克隆下来的用户端来重建服务器上的仓库（虽然可能会丢失某些服务器端的挂钩设置，但是所有版本的数据仍在，详见 <a href="https://git-scm.com/book/zh/v2/1-git-server/_git_on_the_server" target="_blank" rel="external">在服务器上搭建 Git</a> ）。<br><br>克隆仓库的命令格式是 <code>git clone [url]</code> 。<a id="id-zac3hRiws5iB" target="_blank"></a> 比如，要克隆 Git 的可链接库 libgit2，可以用下面的命令：<br><pre><code>$</code> git clone <a href="https://github.com/libgit2/libgit2" target="_blank" rel="external">https://github.com/libgit2/libgit2</a></pre><br>这会在当前目录下创建一个名为 “libgit2” 的目录，并在这个目录下初始化一个 <code>.git</code> 文件夹，从远程仓库拉取下所有数据放入 <code>.git</code> 文件夹，然后从中读取最新版本的文件的拷贝。 如果你进入到这个新建的 <code>libgit2</code> 文件夹，你会发现所有的项目文件已经在里面了，准备就绪等待后续的开发和使用。 如果你想在克隆远程仓库的时候，自定义本地仓库的名字，你可以使用如下命令：<br><pre><code>$</code> git clone <a href="https://github.com/libgit2/libgit2" target="_blank" rel="external">https://github.com/libgit2/libgit2</a> mylibgit</pre><br>这将执行与上一个命令相同的操作，不过在本地创建的仓库名字变为 <code>mylibgit</code>。<br><br>Git 支持多种数据传输协议。 上面的例子使用的是 <code>https://</code> 协议，不过你也可以使用 <code>git://</code> 协议或者使用 SSH 传输协议，比如 <code>user@server:path/to/repo.git</code> 。 <a href="https://git-scm.com/book/zh/v2/1-git-server/_git_on_the_server" target="_blank" rel="external">在服务器上搭建 Git</a>将会介绍所有这些协议在服务器端如何配置使用，以及各种方式之间的利弊。<br><br></div>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/05/10/ef-bc-88-e8-bd-ac-e8-bd-bd-e5-ad-a6-e4-b9-a0-ef-bc-89git-e5-9f-ba-e7-a1-80-e8-8e-b7-e5-8f-96-git-e4-bb-93-e5-ba-93/" data-id="cj359k3z00013fwv7r1paxu8v" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-e7-89-87-e6-ae-b5-e7-ac-94-e8-ae-b0-ef-bc-81-e6-9c-89-e6-96-b0-e9-b2-9c-e4-b8-9c-e8-a5-bf-e9-9a-8f-e6-97-b6-e5-8f-af-e8-83-bd-e6-9b-b4-e6-96-b0-ef-bc-9a-e4-bb-85-e7-94-a8-e4-ba-8e-e8-87-aa-e5-b7-b1" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/05/06/e7-89-87-e6-ae-b5-e7-ac-94-e8-ae-b0-ef-bc-81-e6-9c-89-e6-96-b0-e9-b2-9c-e4-b8-9c-e8-a5-bf-e9-9a-8f-e6-97-b6-e5-8f-af-e8-83-bd-e6-9b-b4-e6-96-b0-ef-bc-9a-e4-bb-85-e7-94-a8-e4-ba-8e-e8-87-aa-e5-b7-b1/" class="article-date">
  <time datetime="2016-05-06T06:30:40.000Z" itemprop="datePublished">2016-05-06</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/未分类/">未分类</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/05/06/e7-89-87-e6-ae-b5-e7-ac-94-e8-ae-b0-ef-bc-81-e6-9c-89-e6-96-b0-e9-b2-9c-e4-b8-9c-e8-a5-bf-e9-9a-8f-e6-97-b6-e5-8f-af-e8-83-bd-e6-9b-b4-e6-96-b0-ef-bc-9a-e4-bb-85-e7-94-a8-e4-ba-8e-e8-87-aa-e5-b7-b1/">片段笔记！(有新鲜东西随时可能更新)：仅用于自己学习笔记</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <div id="wmd-preview-section-19" class="wmd-preview-section preview-content"><br><br>#### 页面请求URL为了避免跳转多次，在URL前加上当前web应用的context上下文路径：<br><br></div><br><div id="wmd-preview-section-20" class="wmd-preview-section preview-content"><br><br>    ${pageContext<span class="hljs-preprocessor">.request</span><span class="hljs-preprocessor">.contextPath</span> }/<code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-21&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 在SpringMVC中处理URL请求参数中文乱码问题：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-22&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-annotation">@RequestMapping</span>(<span class="hljs-string">“/privateChat/{username}”</span>)<br>        <span class="hljs-keyword">public</span> ModelAndView <span class="hljs-title">privateChat</span>(HttpServletRequest request, HttpServletResponse response,<br>                @<span class="hljs-title">PathVariable</span>(“username”) String searchusername) <span class="hljs-keyword">throws</span> Exception{<br>            ModelAndView modelAndView = <span class="hljs-keyword">new</span> ModelAndView();<br>            modelAndView.setViewName(<span class="hljs-string">“privatechat”</span>);<br>            <span class="hljs-javadoc">/<strong><strong><em>*</em></strong></strong> 获取方式 <strong><strong><em>**</em></strong></strong>/</span><br>            <span class="hljs-keyword">byte</span> bb[];<br>            bb = searchusername.getBytes(<span class="hljs-string">“ISO-8859-1”</span>); <span class="hljs-comment">//以”ISO-8859-1”方式解析name字符串</span><br>            searchusername = <span class="hljs-keyword">new</span> String(bb, <span class="hljs-string">“UTF-8”</span>); <span class="hljs-comment">//再用”utf-8”格式表示name</span><br>            System.out.println(<span class="hljs-string">“输出的请求私聊参数：”</span> + searchusername);<br>            <span class="hljs-keyword">return</span> modelAndView;<br>     }<code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-23&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 处理JSON;

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-24&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>@ResponseBody<br>    @RequestMapping(“/testJson”)<br>    public List<span class="hljs-tag">&lt;<span class="hljs-title">User</span>&gt;</span> testJson(){<br>        return userService.getAll();<br>    }<br><br>    <span class="hljs-tag">&lt;<span class="hljs-title">script</span>&gt;</span><span class="javascript"><br>    $(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span><br>        $(<span class="hljs-string">“#testJson”</span>).click(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span><br>            <span class="hljs-keyword">var</span> url = <span class="hljs-string">“this.href”</span>; <span class="hljs-comment">//&lt;a href=”testJson”&gt;&lt;/a&gt;</span><br>            <span class="hljs-keyword">var</span> args = {};<br>            $.post(url, args, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(datas)</span>{</span><br>                <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; datas.length; i++){<br>                    <span class="hljs-keyword">var</span> id = datas[i].id;<br>                    <span class="hljs-keyword">var</span> username = datas[i].username;<br>                    <span class="hljs-comment">//alert(id + “:” + username);</span><br>                }<br>            });<br>            <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>        });<br>    })<br>    </span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span><code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-25&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### Maven项目解决报“java compiler level does not match the version of the installed java project facet”的错误：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-26&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    ##### 方法1: 在该项目的本地目录下的setting配置中修改该文件：org.eclipse.wst.common.project.facet.core.xml 中的以下版本配置即可

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-27&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code> <span class="hljs-tag">&lt;<span class="hljs-title">installed</span> <span class="hljs-attribute">facet</span>=<span class="hljs-value">“java”</span> <span class="hljs-attribute">version</span>=<span class="hljs-value">“1.8”</span>/&gt;</span> <code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-28&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    ##### 方法2: 更好的解决办法是在Eclipse新建maven项目后到项目的buildPath配置中找到Project Facets，然后配置该项目的Project Facets中的Java版本。

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-29&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    ##### 方法3： 在父项目的pom中的 &amp;lt; project &amp;gt; 节点下添加如下的依赖以配置编译环境。

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-30&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>  <span class="hljs-tag">&lt;<span class="hljs-title">build</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">finalName</span>&gt;</span>swift-base<span class="hljs-tag">&lt;/<span class="hljs-title">finalName</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">plugins</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">plugin</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">groupId</span>&gt;</span>org.apache.maven.plugins<span class="hljs-tag">&lt;/<span class="hljs-title">groupId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">artifactId</span>&gt;</span>maven-compiler-plugin<span class="hljs-tag">&lt;/<span class="hljs-title">artifactId</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">version</span>&gt;</span>3.5.1<span class="hljs-tag">&lt;/<span class="hljs-title">version</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">configuration</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-title">source</span>&gt;</span>1.7<span class="hljs-tag">&lt;/<span class="hljs-title">source</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-title">target</span>&gt;</span>1.7<span class="hljs-tag">&lt;/<span class="hljs-title">target</span>&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-title">configuration</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">plugin</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">plugins</span>&gt;</span><br>      <span class="hljs-tag">&lt;/<span class="hljs-title">build</span>&gt;</span><br><br></div>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/05/06/e7-89-87-e6-ae-b5-e7-ac-94-e8-ae-b0-ef-bc-81-e6-9c-89-e6-96-b0-e9-b2-9c-e4-b8-9c-e8-a5-bf-e9-9a-8f-e6-97-b6-e5-8f-af-e8-83-bd-e6-9b-b4-e6-96-b0-ef-bc-9a-e4-bb-85-e7-94-a8-e4-ba-8e-e8-87-aa-e5-b7-b1/" data-id="cj359k3xe000mfwv7c6gk0tqi" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-springmvc-e5-86-99-e4-b8-80-e4-b8-aa-e8-be-93-e5-87-ba-e4-b8-bajackson-e6-a0-bc-e5-bc-8f-e5-a6-82xml-e3-80-81json-e7-9a-84api-e7-9a-84-e5-b0-8f-e7-ac-94-e8-ae-b0" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/05/04/springmvc-e5-86-99-e4-b8-80-e4-b8-aa-e8-be-93-e5-87-ba-e4-b8-bajackson-e6-a0-bc-e5-bc-8f-e5-a6-82xml-e3-80-81json-e7-9a-84api-e7-9a-84-e5-b0-8f-e7-ac-94-e8-ae-b0/" class="article-date">
  <time datetime="2016-05-04T01:59:25.000Z" itemprop="datePublished">2016-05-04</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/SpringMVC/">SpringMVC</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/05/04/springmvc-e5-86-99-e4-b8-80-e4-b8-aa-e8-be-93-e5-87-ba-e4-b8-bajackson-e6-a0-bc-e5-bc-8f-e5-a6-82xml-e3-80-81json-e7-9a-84api-e7-9a-84-e5-b0-8f-e7-ac-94-e8-ae-b0/">SpringMVC写一个输出为Jackson格式(如xml、json)的api的小笔记</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <div id="csdnEditor" class=" ltr"><br><div class="layout-wrapper-l1"><br><div class="layout-wrapper-l2"><br><div class="layout-wrapper-l3"><br><div class="preview-panel"><br><div class="preview-container"><br><div id="preview-contents"><br><div id="wmd-preview-section-19" class="wmd-preview-section preview-content"><br><br>    <span class="hljs-keyword">package</span> swift.edas.web;<br><br>    <span class="hljs-keyword">import</span> java.util.Date;<br><br>    <span class="hljs-keyword">import</span> javax.servlet.http.HttpServletRequest;<br>    <span class="hljs-keyword">import</span> javax.servlet.http.HttpServletResponse;<br><br>    <span class="hljs-keyword">import</span> org.springframework.stereotype.Controller;<br>    <span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;<br>    <span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.ResponseBody;<br><br>    <span class="hljs-keyword">import</span> com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;<br>    <span class="hljs-keyword">import</span> com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;<br><br>    <span class="hljs-annotation">@Controller</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Tests</span> {</span><br><br>        <span class="hljs-annotation">@JacksonXmlRootElement</span>(localName=<span class="hljs-string">“something”</span>)<br>        <span class="hljs-keyword">static</span> class Something {<br>            <span class="hljs-annotation">@JacksonXmlProperty</span>(isAttribute=<span class="hljs-keyword">true</span>)<br>            <span class="hljs-keyword">int</span> id;<br>            String name;<br>            Date time;<br>            <span class="hljs-keyword">public</span> <span class="hljs-title">Something</span>(String name) {<br>                id = (<span class="hljs-keyword">int</span>)(Math.random() * <span class="hljs-number">1000</span>);<br>                <span class="hljs-keyword">this</span>.name = name;<br>                time = <span class="hljs-keyword">new</span> Date();<br>            }<br>            <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getId</span>() {<br>                <span class="hljs-keyword">return</span> id;<br>            }<br>            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setId</span>(<span class="hljs-keyword">int</span> id) {<br>                <span class="hljs-keyword">this</span>.id = id;<br>            }<br>            <span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span>() {<br>                <span class="hljs-keyword">return</span> name;<br>            }<br>            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span>(String name) {<br>                <span class="hljs-keyword">this</span>.name = name;<br>            }<br>            <span class="hljs-keyword">public</span> Date <span class="hljs-title">getTime</span>() {<br>                <span class="hljs-keyword">return</span> time;<br>            }<br>            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setTime</span>(Date time) {<br>                <span class="hljs-keyword">this</span>.time = time;<br>            }<br>        }<br><br>        <span class="hljs-annotation">@RequestMapping</span>(value=<span class="hljs-string">“/test/hello.xml”</span>)<br>        <span class="hljs-keyword">public</span> @ResponseBody Object <span class="hljs-title">helloXml</span>(HttpServletRequest request, HttpServletResponse response) {<br>            <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Something(<span class="hljs-string">“hello”</span>);<br>        }<br><br>        <span class="hljs-annotation">@RequestMapping</span>(value=<span class="hljs-string">“/test/hello.json”</span>)<br>        <span class="hljs-keyword">public</span> @ResponseBody Object <span class="hljs-title">helloJson</span>(HttpServletRequest request, HttpServletResponse response) {<br>            <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Something(<span class="hljs-string">“hello”</span>);<br>        }<br><br>    }<br><br></div><br><div id="wmd-preview-section-footnotes" class="preview-content"></div><br></div><br></div><br></div><br></div><br><div class="extension-preview-buttons animate closed"><br><div class="btn-group drag-me dropup" title="这里可以拖拽"></div><br><div class="btn-group dropup"></div><br><div class="btn-group dropup"></div><br><div class="btn-group dropup"><button class="btn btn-success dropdown-toggle stat-button" title="统计信息" data-toggle="dropdown"> <span class="value">1232</span></button></div><br></div><br></div><br></div><br></div>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/05/04/springmvc-e5-86-99-e4-b8-80-e4-b8-aa-e8-be-93-e5-87-ba-e4-b8-bajackson-e6-a0-bc-e5-bc-8f-e5-a6-82xml-e3-80-81json-e7-9a-84api-e7-9a-84-e5-b0-8f-e7-ac-94-e8-ae-b0/" data-id="cj359k407001gfwv7yarckp5h" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-e7-ae-80-e5-8d-95-e6-95-b4-e5-90-88springspringmvcmybatis" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/04/22/e7-ae-80-e5-8d-95-e6-95-b4-e5-90-88springspringmvcmybatis/" class="article-date">
  <time datetime="2016-04-22T06:20:25.000Z" itemprop="datePublished">2016-04-22</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Mybatis/">Mybatis</a>►<a class="article-category-link" href="/categories/Mybatis/Spring/">Spring</a>►<a class="article-category-link" href="/categories/Mybatis/Spring/SpringMVC/">SpringMVC</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/04/22/e7-ae-80-e5-8d-95-e6-95-b4-e5-90-88springspringmvcmybatis/">简单整合Spring+SpringMVC+Mybatis</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <div id="wmd-preview-section-18" class="wmd-preview-section preview-content"><br><br>最近一直想总结一下Spring+SpringMVC+Mybatis的整合过程，也便于以后忘了什么细节的东西却要用到的时候面对海量的搜索结果不好选择。<br>下面是我参考一些文档博文，自己动手总结出来的一些东西。浅显勿怪！<br><br>首先是相关框架的职责功能：<br>》SpringMVC：负责表现层<br>》Service接口：处理业务<br>》Mapper：持久层(相当于DAO接口)<br>》Spring：将各个层整合，管理持久层的Mapper，管理业务层的Service，管理表现层的Handler。<br>》》在Handler中可以调用Service接口，在Service接口中可以调用Mapper接口。(为了记忆我通常用“A-S-D”来记住调用关系)<br><br></div><br><div id="wmd-preview-section-19" class="wmd-preview-section preview-content"><br><br>### 下面是具体的整合思路：<br><br></div><br><div id="wmd-preview-section-20" class="wmd-preview-section preview-content"><br><br>#### 第一步：整合DAO层(Mybatis和Spring整合，通过Spring管理Mapper接口)：使用Mapper的扫描器自动扫描Mapper接口在Spring容器中注册。<br><br></div><br><div id="wmd-preview-section-21" class="wmd-preview-section preview-content"><br><br>#### 第二步：整合Service层(通过Spring管理Service接口)：使用配置方式将Service接口配置在Spring配置文件中，实现事务控制。<br><br></div><br><div id="wmd-preview-section-22" class="wmd-preview-section preview-content"><br><br>#### 第三步：整合SpringMVC(因为SpringMVC是Spring的一个子模块，故而无需进一步做整合操作)。<br><br></div><br><div id="wmd-preview-section-23" class="wmd-preview-section preview-content"><br><br>### 接下来做具体的环境搭建操作<br><br></div><br><div id="wmd-preview-section-24" class="wmd-preview-section preview-content"><br><br>#### 1. 新建动态web工程，建立目录结构并导入包括spring、mybatis、c3p0、mysql等相关的jar包。<br><br>以下是我的目录结构：<br><img src="http://img.blog.csdn.net/20160422132741512" alt="这里写图片描述"><br><br></div><br><div id="wmd-preview-section-25" class="wmd-preview-section preview-content"><br><br>#### 2. 配置web.xml文件：<br><br>》1.配置Spring容器：ContextLoaderListener及spring配置文件的路径地址<br>在这里我采用了restful风格的applicationContext-<em>.xml的spring配置文件的配置<br>》2.配置DispatcherServlet前端控制器并指明前端控制器的配置文件上下文配置文件的位置<br>在这里我不使用默认定义命名，而是使用了自己定义的配置文件名：springmvc.xml<br>》3.可以配置编码过滤器<br>具体代码如下：<br><br></em></div><br><div id="wmd-preview-section-26" class="wmd-preview-section preview-content"><br><br>    <span class="hljs-pi">&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">web-app</span> <span class="hljs-attribute">xmlns:xsi</span>=<span class="hljs-value">“<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="external">http://www.w3.org/2001/XMLSchema-instance</a>“</span> <span class="hljs-attribute">xmlns</span>=<span class="hljs-value">“<a href="http://java.sun.com/xml/ns/javaee" target="_blank" rel="external">http://java.sun.com/xml/ns/javaee</a>“</span> <span class="hljs-attribute">xsi:schemaLocation</span>=<span class="hljs-value">“<a href="http://java.sun.com/xml/ns/javaee" target="_blank" rel="external">http://java.sun.com/xml/ns/javaee</a> <a href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" target="_blank" rel="external">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a>“</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“WebApp_ID”</span> <span class="hljs-attribute">version</span>=<span class="hljs-value">“2.5”</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-title">display-name</span>&gt;</span>ssm<span class="hljs-tag">&lt;/<span class="hljs-title">display-name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-title">welcome-file-list</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">welcome-file</span>&gt;</span>index.jsp<span class="hljs-tag">&lt;/<span class="hljs-title">welcome-file</span>&gt;</span><br>      <span class="hljs-tag">&lt;/<span class="hljs-title">welcome-file-list</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 配置Spring容器 –&gt;</span><br>      <span class="hljs-comment">&lt;!– needed for ContextLoaderListener –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">context-param</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">param-name</span>&gt;</span>contextConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-title">param-name</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">param-value</span>&gt;</span>classpath:spring/applicationContext-.xml<span class="hljs-tag">&lt;/<span class="hljs-title">param-value</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">context-param</span>&gt;</span><br>        <span class="hljs-comment">&lt;!– Bootstraps the root web application context before servlet initialization –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">listener</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">listener-class</span>&gt;</span>org.springframework.web.context.ContextLoaderListener<span class="hljs-tag">&lt;/<span class="hljs-title">listener-class</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">listener</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 配置前端控制器 –&gt;</span><br>        <span class="hljs-comment">&lt;!– The front controller of this Spring Web application, responsible for handling all application requests –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">servlet</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">servlet-name</span>&gt;</span>springmvc<span class="hljs-tag">&lt;/<span class="hljs-title">servlet-name</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">servlet-class</span>&gt;</span>org.springframework.web.servlet.DispatcherServlet<span class="hljs-tag">&lt;/<span class="hljs-title">servlet-class</span>&gt;</span><br>            <span class="hljs-comment">&lt;!– 加载前端控制器配置文件 上下文配置文件的位置 –&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">init-param</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">param-name</span>&gt;</span>contextConfigLocation<span class="hljs-tag">&lt;/<span class="hljs-title">param-name</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">param-value</span>&gt;</span>classpath:spring/springmvc.xml<span class="hljs-tag">&lt;/<span class="hljs-title">param-value</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">init-param</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">load-on-startup</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-title">load-on-startup</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">servlet</span>&gt;</span><br>        <span class="hljs-comment">&lt;!– Map all requests to the DispatcherServlet for handling –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">servlet-mapping</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">servlet-name</span>&gt;</span>springmvc<span class="hljs-tag">&lt;/<span class="hljs-title">servlet-name</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">url-pattern</span>&gt;</span>/<span class="hljs-tag">&lt;/<span class="hljs-title">url-pattern</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">servlet-mapping</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 编码过滤配置 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">filter</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">filter-name</span>&gt;</span>CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-title">filter-name</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">filter-class</span>&gt;</span>org.springframework.web.filter.CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-title">filter-class</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">init-param</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">param-name</span>&gt;</span>encoding<span class="hljs-tag">&lt;/<span class="hljs-title">param-name</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">param-value</span>&gt;</span>utf-8<span class="hljs-tag">&lt;/<span class="hljs-title">param-value</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">init-param</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">filter</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">filter-mapping</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">filter-name</span>&gt;</span>CharacterEncodingFilter<span class="hljs-tag">&lt;/<span class="hljs-title">filter-name</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">url-pattern</span>&gt;</span>/<em><span class="hljs-tag">&lt;/<span class="hljs-title">url-pattern</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">filter-mapping</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">web-app</span>&gt;</span><code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-27&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 3\. 配置applicationContext.xml文件

    》1.在web.xml指定的命名方式和路径下在spring目录下新建applicationContext-dao.xml配置文件：
    》2.配置加载db.properties：指定配置文件路径
    》3.配置数据源：配置dataSource及其username，password，driverClass等属性
    》4.配置SqlSessionFactoryBean：配置SqlSessionFactoryBean的bean并引用dataSource和加载mybatis的全局配置文件sqlMapConfig.xml的路径位置
    》5.配置Mapper扫描器：配置mapper扫描器的bean并配置其扫描mapper的包basePackage的路径，同时在设置其sqlSessionFactoryBeanName属性时注意不能使用ref，否则会因为前面加载配置文件导致这里报错，要使用value设置属性值。
    具体代码如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-28&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-pi">&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">beans</span> <span class="hljs-attribute">xmlns</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a>“</span><br>        <span class="hljs-attribute">xmlns:xsi</span>=<span class="hljs-value">“<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="external">http://www.w3.org/2001/XMLSchema-instance</a>“</span><br>        <span class="hljs-attribute">xmlns:context</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/context" target="_blank" rel="external">http://www.springframework.org/schema/context</a>“</span><br>        <span class="hljs-attribute">xsi:schemaLocation</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd" target="_blank" rel="external">http://www.springframework.org/schema/beans/spring-beans.xsd</a><br>            <a href="http://www.springframework.org/schema/context" target="_blank" rel="external">http://www.springframework.org/schema/context</a> <a href="http://www.springframework.org/schema/context/spring-context-4.2.xsd" target="_blank" rel="external">http://www.springframework.org/schema/context/spring-context-4.2.xsd</a>“</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 加载数据库配置文件 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">context:property-placeholder</span> <span class="hljs-attribute">location</span>=<span class="hljs-value">“classpath:db.properties”</span>/&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 配置数据源 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“dataSource”</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“com.mchange.v2.c3p0.ComboPooledDataSource”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“user”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“${jdbc.username}”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“password”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“${jdbc.password}”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“jdbcUrl”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“${jdbc.jdbcUrl}”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“driverClass”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“${jdbc.driverClass}”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 配置SqlSessionFactoryBean –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“sqlSessionFactoryBean”</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“org.mybatis.spring.SqlSessionFactoryBean”</span>&gt;</span><br>            <span class="hljs-comment">&lt;!– 数据源 –&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“dataSource”</span> <span class="hljs-attribute">ref</span>=<span class="hljs-value">“dataSource”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>            <span class="hljs-comment">&lt;!– 加载mybatis的全局配置文件 –&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“configLocation”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“classpath:mybatis/sqlMapConfig.xml”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 配置mapper扫描器 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“org.mybatis.spring.mapper.MapperScannerConfigurer”</span>&gt;</span><br>            <span class="hljs-comment">&lt;!– 扫描mapper的包路径, 如果需要扫描多个包中间用半角逗号隔开 –&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“basePackage”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“cn.hankchan.mapper”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>            <span class="hljs-comment">&lt;!– 不能使用ref=”” 因为上面加载配置文件导致这里引用会报错 –&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“sqlSessionFactoryBeanName”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“sqlSessionFactoryBean”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">beans</span>&gt;</span><code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-29&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 4\. 配置applicationContext-service.xml配置文件

    》配置扫描Service的包路径：
    只用于加载Service组件。
    具体代码如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-30&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-pi">&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">beans</span> <span class="hljs-attribute">xmlns</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a>“</span><br>        <span class="hljs-attribute">xmlns:xsi</span>=<span class="hljs-value">“<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="external">http://www.w3.org/2001/XMLSchema-instance</a>“</span><br>        <span class="hljs-attribute">xmlns:context</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/context" target="_blank" rel="external">http://www.springframework.org/schema/context</a>“</span><br>        <span class="hljs-attribute">xsi:schemaLocation</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd" target="_blank" rel="external">http://www.springframework.org/schema/beans/spring-beans.xsd</a><br>            <a href="http://www.springframework.org/schema/context" target="_blank" rel="external">http://www.springframework.org/schema/context</a> <a href="http://www.springframework.org/schema/context/spring-context-4.2.xsd" target="_blank" rel="external">http://www.springframework.org/schema/context/spring-context-4.2.xsd</a>“</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 扫描Service –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">context:component-scan</span> <span class="hljs-attribute">base-package</span>=<span class="hljs-value">“cn.hankchan.service.impl”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">context:component-scan</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">beans</span>&gt;</span><code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-31&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 5\. 配置applicationContext-transaction.xml文件

    》主要用于事务处理。具体用途请自己查阅资料学习相关的知识，我自己忘得差不多了。就不废话了，直接上代码。(需要说明的是：因为一些不记得什么原因的原因，这个文件有一个配置的错误，所以我是直接注掉不使用事务管理的。留待后续再解决。)
    代码如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-32&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-pi">&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">beans</span> <span class="hljs-attribute">xmlns</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a>“</span><br>        <span class="hljs-attribute">xmlns:xsi</span>=<span class="hljs-value">“<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="external">http://www.w3.org/2001/XMLSchema-instance</a>“</span><br>        <span class="hljs-attribute">xmlns:tx</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/tx" target="_blank" rel="external">http://www.springframework.org/schema/tx</a>“</span><br>        <span class="hljs-attribute">xmlns:aop</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/aop" target="_blank" rel="external">http://www.springframework.org/schema/aop</a>“</span><br>        <span class="hljs-attribute">xsi:schemaLocation</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd" target="_blank" rel="external">http://www.springframework.org/schema/beans/spring-beans.xsd</a><br>            <a href="http://www.springframework.org/schema/aop" target="_blank" rel="external">http://www.springframework.org/schema/aop</a> <a href="http://www.springframework.org/schema/aop/spring-aop-4.2.xsd" target="_blank" rel="external">http://www.springframework.org/schema/aop/spring-aop-4.2.xsd</a><br>            <a href="http://www.springframework.org/schema/tx" target="_blank" rel="external">http://www.springframework.org/schema/tx</a> <a href="http://www.springframework.org/schema/tx/spring-tx-4.2.xsd" target="_blank" rel="external">http://www.springframework.org/schema/tx/spring-tx-4.2.xsd</a>“</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 事务管理器 对mybatis操作数据库事务控制，spring使用jdbc的事务控制类 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“transactionManager”</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“org.springframework.jdbc.datasource.DataSourceTransactionManager”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“dataSource”</span> <span class="hljs-attribute">ref</span>=<span class="hljs-value">“dataSource”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 通知 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">tx:advice</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“txAdvice”</span> <span class="hljs-attribute">transaction-manager</span>=<span class="hljs-value">“transactionManager”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">tx:attributes</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“save</span></span></em>“ <span class="hljs-attribute">propagation</span>=<span class="hljs-value">“REQUIRED”</span>/&gt;<br>                <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“delete<em>“</em></span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">“REQUIRED”</span>/&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“insert“</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">“REQUIRED”</span>/&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“update<em>“</em></span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">“REQUIRED”</span>/&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“find“</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">“SUPPORTS”</span> <span class="hljs-attribute">read-only</span>=<span class="hljs-value">“true”</span>/&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“get<em>“</em></span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">“SUPPORTS”</span> <span class="hljs-attribute">read-only</span>=<span class="hljs-value">“true”</span>/&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-title">tx:method</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“select“</span> <span class="hljs-attribute">propagation</span>=<span class="hljs-value">“SUPPORTS”</span> <span class="hljs-attribute">read-only</span>=<span class="hljs-value">“true”</span>/&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-title">tx:attributes</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">tx:advice</span>&gt;</span><br>      <span class="hljs-comment">&lt;!– AOP –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">aop:config</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">aop:advisor</span> <span class="hljs-attribute">advice-ref</span>=<span class="hljs-value">“txAdvice”</span><br>                <span class="hljs-attribute">pointcut</span>=<span class="hljs-value">“execution(<em> cn.hankchan.service.impl.</em>.*(..))”</span>/&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">aop:config</span>&gt;</span><br><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">beans</span>&gt;</span><code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-33&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 6\. 接下来配置前端控制器的配置文件springmvc.xml

    》1.配置扫描Controller的路径
    》2.配置注解的映射器和适配器
    》3.配置视图解析器及响应路径的前后缀
    这是很基础的东西，不多解释，直接上代码：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-34&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-pi">&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">beans</span> <span class="hljs-attribute">xmlns</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a>“</span><br>        <span class="hljs-attribute">xmlns:xsi</span>=<span class="hljs-value">“<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank" rel="external">http://www.w3.org/2001/XMLSchema-instance</a>“</span><br>        <span class="hljs-attribute">xmlns:context</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/context" target="_blank" rel="external">http://www.springframework.org/schema/context</a>“</span><br>        <span class="hljs-attribute">xmlns:mvc</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/mvc" target="_blank" rel="external">http://www.springframework.org/schema/mvc</a>“</span><br>        <span class="hljs-attribute">xsi:schemaLocation</span>=<span class="hljs-value">“<a href="http://www.springframework.org/schema/mvc" target="_blank" rel="external">http://www.springframework.org/schema/mvc</a> <a href="http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd" target="_blank" rel="external">http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd</a><br>            <a href="http://www.springframework.org/schema/beans" target="_blank" rel="external">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd" target="_blank" rel="external">http://www.springframework.org/schema/beans/spring-beans.xsd</a><br>            <a href="http://www.springframework.org/schema/context" target="_blank" rel="external">http://www.springframework.org/schema/context</a> <a href="http://www.springframework.org/schema/context/spring-context-4.2.xsd" target="_blank" rel="external">http://www.springframework.org/schema/context/spring-context-4.2.xsd</a>“</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 扫描Controller –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">context:component-scan</span> <span class="hljs-attribute">base-package</span>=<span class="hljs-value">“cn.hankchan.controller”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">context:component-scan</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 配置注解的映射器和适配器 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">mvc:annotation-driven</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">mvc:annotation-driven</span>&gt;</span><br><br>      <span class="hljs-comment">&lt;!– 配置视图解析器 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">bean</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">“org.springframework.web.servlet.view.InternalResourceViewResolver”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“prefix”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“/WEB-INF/jsp/“</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">property</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“suffix”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“.jsp”</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">bean</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">beans</span>&gt;</span><code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-35&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 7\. 最后我们配置mybatis的配置文件：sqlMapConfig.xml

    》主要用于配置mybatis框架的一些设置如配置pojo类的别名、开启二级缓存等等。
    代码如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-36&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code><span class="hljs-pi">&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</span><br>    <span class="hljs-doctype">&lt;!DOCTYPE configuration<br>    PUBLIC “-//mybatis.org//DTD Config 3.0//EN”<br>    “<a href="http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&amp;gt" target="_blank" rel="external">http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&amp;gt</a>;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">configuration</span>&gt;</span><br>        <span class="hljs-comment">&lt;!– 全局setting配置，根据需要添加 –&gt;</span><br>        <span class="hljs-comment">&lt;!– 配置别名 –&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">typeAliases</span>&gt;</span><br>            <span class="hljs-comment">&lt;!– 批量扫描设置别名 –&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">package</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“cn.hankchan.po”</span>/&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">typeAliases</span>&gt;</span><br>        <span class="hljs-comment">&lt;!– 配置Mapper<br>            备注: 由于使用Spring整合mybatis的整合包进行mapper扫描，这里无需配置<br>            必须遵循mapper.xml和mapper.java文件同名且在同一文件目录下<br>         –&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">configuration</span>&gt;</span><code>&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-37&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;

    #### 8\. 编写配置db.properties、log4j.properties等相关的配置文件

    根据情况自己设置相关的参数，我的相关代码如下：
    db.properties：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-38&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>jdbc<span class="hljs-preprocessor">.username</span>=root<br>    jdbc<span class="hljs-preprocessor">.password</span>=<br>    jdbc<span class="hljs-preprocessor">.jdbcUrl</span>=<span class="hljs-keyword">com</span><span class="hljs-preprocessor">.mysql</span><span class="hljs-preprocessor">.jdbc</span><span class="hljs-preprocessor">.Driver</span><br>    jdbc<span class="hljs-preprocessor">.driverClass</span>=jdbc:mysql:///qxt<code>&lt;/pre&gt;
    log4j.properties：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-39&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>log4j<span class="hljs-preprocessor">.rootLogger</span>=DEBUG, stdout<br>    <span class="hljs-preprocessor"># Console output…</span><br>    log4j<span class="hljs-preprocessor">.appender</span><span class="hljs-preprocessor">.stdout</span>=org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.log</span>4j<span class="hljs-preprocessor">.ConsoleAppender</span><br>    log4j<span class="hljs-preprocessor">.appender</span><span class="hljs-preprocessor">.stdout</span><span class="hljs-preprocessor">.layout</span>=org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.log</span>4j<span class="hljs-preprocessor">.PatternLayout</span><br>    log4j<span class="hljs-preprocessor">.appender</span><span class="hljs-preprocessor">.stdout</span><span class="hljs-preprocessor">.layout</span><span class="hljs-preprocessor">.ConversionPattern</span>=%<span class="hljs-number">5</span>p [%t] - %m%n<br><br>到了这里，整合SSM的环境基本上就搭建完成。<br>我在相关目录下新建了XxxPo.java，XxxMapper.java，XxxMapper.xml，XxxController.java，XxxService.java，XxxServiceImpl.java用于测试。具体的类可以根据需求自己设计添加。<br>运行一次如果不报错的话说明这个整合过程是成功了。<br>拖了好一阵子，终于把这个整合思路过程自己记录了下路，BINGO！！<br><br></div>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/04/22/e7-ae-80-e5-8d-95-e6-95-b4-e5-90-88springspringmvcmybatis/" data-id="cj359k3xx000rfwv71gr5a3w7" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-springmvc-e9-80-9a-e8-bf-87-e4-b8-8d-e5-90-8c-e7-9a-84url-e8-bf-94-e5-9b-9ejson-e5-af-b9-e8-b1-a1-e5-b9-b6-e5-9c-a8-e5-89-8d-e7-ab-af-e6-98-be-e7-a4-ba-e7-9a-84-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/04/12/springmvc-e9-80-9a-e8-bf-87-e4-b8-8d-e5-90-8c-e7-9a-84url-e8-bf-94-e5-9b-9ejson-e5-af-b9-e8-b1-a1-e5-b9-b6-e5-9c-a8-e5-89-8d-e7-ab-af-e6-98-be-e7-a4-ba-e7-9a-84-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95/" class="article-date">
  <time datetime="2016-04-12T02:28:42.000Z" itemprop="datePublished">2016-04-12</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/未分类/">未分类</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2016/04/12/springmvc-e9-80-9a-e8-bf-87-e4-b8-8d-e5-90-8c-e7-9a-84url-e8-bf-94-e5-9b-9ejson-e5-af-b9-e8-b1-a1-e5-b9-b6-e5-9c-a8-e5-89-8d-e7-ab-af-e6-98-be-e7-a4-ba-e7-9a-84-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95/">SpringMVC通过不同的url返回Json对象并在前端显示的解决方法</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <div id="wmd-preview-section-18" class="wmd-preview-section preview-content"><br><br>通过请求不同的url返回Json对象并在前端显示的解决方法：这是最近学习前端的一个小demo，需求是：处理三个不同url的页面中的json对象信息，让用户通过在页面选择查询类型和查询条数就可以以表格形式显示相关的Json对象信息。<br>话不多说，上代码。<br><br></div><br><div id="wmd-preview-section-19" class="wmd-preview-section preview-content"><br><br>    <span class="hljs-tag">&lt;<span class="hljs-title">html</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">meta</span> <span class="hljs-attribute">charset</span>=<span class="hljs-value">“UTF-8”</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">title</span>&gt;</span>返回JSON对象表格<span class="hljs-tag">&lt;/<span class="hljs-title">title</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">“text/javascript”</span>&gt;</span><span class="javascript"><br>        <span class="hljs-keyword">var</span> selectSuffix;<br>        <span class="hljs-keyword">var</span> list;<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">loadJsonDoc</span><span class="hljs-params">()</span>{</span><br>            getList();<br>            <span class="hljs-keyword">var</span> suffix = getSelectVal();<br>            <span class="hljs-keyword">var</span> index = location.href.lastIndexOf(<span class="hljs-string">“/“</span>);<br>            <span class="hljs-keyword">var</span> urlPrefix = location.href.substring(<span class="hljs-number">0</span>, index + <span class="hljs-number">1</span>);<br>            <span class="hljs-keyword">var</span> url = urlPrefix + suffix;<br>            <span class="hljs-keyword">var</span> xmlhttp = <span class="hljs-keyword">new</span> XMLHttpRequest();<br>            xmlhttp.onreadystatechange=<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span>{</span><br>                <span class="hljs-keyword">if</span>(xmlhttp.readyState == <span class="hljs-number">4</span> &amp;&amp; xmlhttp.status == <span class="hljs-number">200</span>){<br>                    <span class="hljs-keyword">var</span> jsonText = xmlhttp.responseText;<br>                    <span class="hljs-comment">//获取Json对象</span><br>                    JSONObject = <span class="hljs-built_in">eval</span>(<span class="hljs-string">“(“</span> + jsonText + <span class="hljs-string">“)”</span>); <span class="hljs-comment">//不使用var声明，就算再function体内，只要执行过就成为全局变量</span><br>                    <span class="hljs-comment">//根据输入条件获取参数并输出数据</span><br>                    <span class="hljs-comment">//document.getElementById(“text”).innerHTML = document.write(jsonText);</span><br>                    print(list);<br>                }<br>            }<br>            xmlhttp.open(<span class="hljs-string">“GET”</span>,url,<span class="hljs-literal">true</span>);<br>            xmlhttp.send();<br>        }<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getList</span><span class="hljs-params">()</span>{</span><br>            list = document.getElementById(<span class="hljs-string">“recent”</span>).value;<br>            <span class="hljs-keyword">return</span> list;<br>        }<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getSelectVal</span><span class="hljs-params">()</span>{</span><br>            selectSuffix = document.getElementById(<span class="hljs-string">“selectQuery”</span>).value;<br>            <span class="hljs-keyword">return</span> selectSuffix;<br>        }<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">print</span><span class="hljs-params">(a)</span>{</span><br>            <span class="hljs-comment">//定义获取Json对象</span><br>            document.write(<span class="hljs-string">“&lt;br&gt;&lt;a href=’success.html’&gt;返回&lt;/a&gt;”</span>);  <span class="hljs-comment">//返回查询首页</span><br>            document.write(<span class="hljs-string">“&lt;table border=’1’ cellpadding=’0’ cellpadding=’10’&gt;”</span><br>                    + <span class="hljs-string">“&lt;tr&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“num”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“key”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“total”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“min”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“max”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“average”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;/tr&gt;”</span>);<br>            <span class="hljs-keyword">var</span> count = <span class="hljs-number">0</span>;<br>            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> key <span class="hljs-keyword">in</span> JSONObject.result){  <span class="hljs-comment">//输出每个Json对象的信息</span><br>                <span class="hljs-keyword">var</span> jVals = JSONObject.result;<br>                count++;<br>                document.write(<span class="hljs-string">“&lt;tr&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + count + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + key + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].total + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].min + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].max + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].average + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;/tr&gt;”</span>);<br>                <span class="hljs-keyword">if</span>(count == a){  <span class="hljs-comment">//默认输出20条数据</span><br>                    <span class="hljs-keyword">break</span>;<br>                }<br>            }<br>            document.write(<span class="hljs-string">“&lt;/table&gt;”</span>);<br><br>        }<br>    </span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-title">h2</span>&gt;</span>Json Message<span class="hljs-tag">&lt;/<span class="hljs-title">h2</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“text”</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">select</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“selectQuery”</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“all.json”</span> <span class="hljs-attribute">onclick</span>=<span class="hljs-value">“getSelectVal()”</span>&gt;</span>all<span class="hljs-tag">&lt;/<span class="hljs-title">option</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“batch.json”</span> <span class="hljs-attribute">onclick</span>=<span class="hljs-value">“getSelectVal()”</span>&gt;</span>batch<span class="hljs-tag">&lt;/<span class="hljs-title">option</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">option</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“image.json”</span> <span class="hljs-attribute">onclick</span>=<span class="hljs-value">“getSelectVal()”</span>&gt;</span>image<span class="hljs-tag">&lt;/<span class="hljs-title">option</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">select</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-title">form</span> <span class="hljs-attribute">method</span>=<span class="hljs-value">“get”</span>&gt;</span><br>            请输入查询条数: <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">“recent”</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">“text”</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">“recent”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“”</span>/&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">“submit”</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">“确认”</span> <span class="hljs-attribute">onclick</span>=<span class="hljs-value">“loadJsonDoc()”</span>/&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">form</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-title">html</span>&gt;</span><code>&lt;/pre&gt;
    附上三个Json的页面数据：
    all.json(已经做了格式化处理)页面如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-20&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>{<br>        “<span class="hljs-attribute">elapsed</span>“: <span class="hljs-value"><span class="hljs-number">5</span></span>,<br>        “<span class="hljs-attribute">result</span>“: <span class="hljs-value">{<br>            “<span class="hljs-attribute">Batch</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">6</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">200</span><br>            },<br>            “<span class="hljs-attribute">Batch(1)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">46</span><br>            },<br>            “<span class="hljs-attribute">Batch(2)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">2</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">75</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">78</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">76</span><br>            },<br>            “<span class="hljs-attribute">Batch(20)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">384</span><br>            },<br>            “<span class="hljs-attribute">Batch(24)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">2</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">295</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">327</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">311</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">15</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">5</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">164</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(1)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">5</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">78</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">66</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(2)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">125</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">125</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">125</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(6)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">3</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">360</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">370</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(8)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">6</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">5</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">326</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">149</span><br>            },<br>            “<span class="hljs-attribute">Image</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">93</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">25</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">172</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">51</span><br>            },<br>            “<span class="hljs-attribute">Image(1536x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">3</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">25</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">37</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">30</span><br>            },<br>            “<span class="hljs-attribute">Image(1792x1280)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">7</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">36</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">71</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">46</span><br>            },<br>            “<span class="hljs-attribute">Image(1792x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">21</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">26</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">72</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">45</span><br>            },<br>            “<span class="hljs-attribute">Image(2048x1280)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">40</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">40</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">40</span><br>            },<br>            “<span class="hljs-attribute">Image(2048x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">43</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">32</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">172</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">52</span><br>            },<br>            “<span class="hljs-attribute">Image(2048x1792)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">16</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">53</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">169</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">65</span><br>            },<br>            “<span class="hljs-attribute">Image(2304x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">2</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">50</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">69</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">59</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">300</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">0</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">163</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">35</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1536x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">9</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">18</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">35</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">23</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1792x2)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">7</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">0</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">0</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1792x426)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">21</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">20</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">55</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">32</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1792x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">63</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">21</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">67</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">32</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x1)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">16</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">0</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">22</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">1</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x426)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">34</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">34</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">34</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">129</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">25</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">156</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">39</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x597)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">48</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">29</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">163</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">47</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2304x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">6</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">33</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">59</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">47</span><br>            },<br>            “<span class="hljs-attribute">Row</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">172</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">13</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">53</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">22</span><br>            }<br>        }</span>,<br>        “<span class="hljs-attribute">command</span>“: <span class="hljs-value"><span class="hljs-string">“tail -n 500 /home/admin/logs/swift.log”</span></span>,<br>        “<span class="hljs-attribute">ok</span>“: <span class="hljs-value"><span class="hljs-literal">true</span><br>    </span>}<code>&lt;/pre&gt;
    batch.json页面如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-21&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>{<br>        “<span class="hljs-attribute">elapsed</span>“: <span class="hljs-value"><span class="hljs-number">5</span></span>,<br>        “<span class="hljs-attribute">result</span>“: <span class="hljs-value">{<br>            “<span class="hljs-attribute">Batch</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">6</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">200</span><br>            },<br>            “<span class="hljs-attribute">Batch(1)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">46</span><br>            },<br>            “<span class="hljs-attribute">Batch(2)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">2</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">75</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">78</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">76</span><br>            },<br>            “<span class="hljs-attribute">Batch(20)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">384</span><br>            },<br>            “<span class="hljs-attribute">Batch(24)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">2</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">295</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">327</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">311</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">15</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">5</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">164</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(1)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">5</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">46</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">78</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">66</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(2)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">125</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">125</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">125</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(6)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">3</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">360</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">384</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">370</span><br>            },<br>            “<span class="hljs-attribute">BatchSlice(8)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">6</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">5</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">326</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">149</span><br>            }<br>        }</span>,<br>        “<span class="hljs-attribute">command</span>“: <span class="hljs-value"><span class="hljs-string">“tail -n 500 /home/admin/logs/swift.log”</span></span>,<br>        “<span class="hljs-attribute">ok</span>“: <span class="hljs-value"><span class="hljs-literal">true</span><br>    </span>}<code>&lt;/pre&gt;
    image.json页面如下：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-22&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>{<br>        “<span class="hljs-attribute">elapsed</span>“: <span class="hljs-value"><span class="hljs-number">10</span></span>,<br>        “<span class="hljs-attribute">result</span>“: <span class="hljs-value">{<br>            “<span class="hljs-attribute">Image</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">93</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">25</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">172</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">51</span><br>            },<br>            “<span class="hljs-attribute">Image(1536x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">3</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">25</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">37</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">30</span><br>            },<br>            “<span class="hljs-attribute">Image(1792x1280)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">7</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">36</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">71</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">46</span><br>            },<br>            “<span class="hljs-attribute">Image(1792x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">21</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">26</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">72</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">45</span><br>            },<br>            “<span class="hljs-attribute">Image(2048x1280)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">40</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">40</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">40</span><br>            },<br>            “<span class="hljs-attribute">Image(2048x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">43</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">32</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">172</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">52</span><br>            },<br>            “<span class="hljs-attribute">Image(2048x1792)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">16</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">53</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">169</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">65</span><br>            },<br>            “<span class="hljs-attribute">Image(2304x1536)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">2</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">50</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">69</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">59</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">300</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">0</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">163</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">35</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1536x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">9</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">18</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">35</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">23</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1792x2)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">7</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">0</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">0</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1792x426)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">21</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">20</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">55</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">32</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(1792x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">63</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">21</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">67</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">32</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x1)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">16</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">0</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">22</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">1</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x426)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">1</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">34</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">34</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">34</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">129</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">25</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">156</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">39</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2048x597)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">48</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">29</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">163</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">47</span><br>            },<br>            “<span class="hljs-attribute">ImageSlice(2304x512)</span>“: {<br>                “<span class="hljs-attribute">total</span>“: <span class="hljs-number">6</span>,<br>                “<span class="hljs-attribute">min</span>“: <span class="hljs-number">33</span>,<br>                “<span class="hljs-attribute">max</span>“: <span class="hljs-number">59</span>,<br>                “<span class="hljs-attribute">average</span>“: <span class="hljs-number">47</span><br>            }<br>        }</span>,<br>        “<span class="hljs-attribute">command</span>“: <span class="hljs-value"><span class="hljs-string">“tail -n 500 /home/admin/logs/swift.log”</span></span>,<br>        “<span class="hljs-attribute">ok</span>“: <span class="hljs-value"><span class="hljs-literal">true</span><br>    </span>}<code>&lt;/pre&gt;
    刚刚开始接触前端，比较浅薄。具体学习心得待后续再做更新。。

    ——————————–2016.04.16（周日）—————————————
    上次的这些代码是第一次写前端代码，之前从未接触，所以很粗糙。后面因为赶时间，稍作修改后就提交了，也就没有太多复杂的东西。但是是一次不错的学习体验。
    以下是后来稍作修改最后提交的html页面代码：

    &lt;/div&gt;
    &lt;div id=&quot;wmd-preview-section-23&quot; class=&quot;wmd-preview-section preview-content&quot;&gt;
    &lt;pre class=&quot;prettyprint&quot;&gt;</code>&lt;!DOCTYPE html&gt;<br>    &lt;html&gt;<br>    &lt;head&gt;<br>    &lt;meta charset=<span class="hljs-string">“UTF-8”</span>&gt;<br>    &lt;title&gt;Insert title here&lt;/title&gt;<br>    &lt;script src=<span class="hljs-string">“<a href="http://libs.baidu.com/jquery/1.10.2/jquery.min.js" target="_blank" rel="external">http://libs.baidu.com/jquery/1.10.2/jquery.min.js</a>“</span>&gt;&lt;/script&gt;<br>    &lt;script type=<span class="hljs-string">“text/javascript”</span>&gt;<br>    &lt;!– <span class="hljs-number">2016.04</span><span class="hljs-number">.13</span> <span class="hljs-number">23</span>:<span class="hljs-number">18</span> –&gt;<br>    &lt;!– 说明: 默认请求的Json页面跟本页面在同一个文件夹下, 否则需要修改相应的方法 –&gt;<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getNum</span><span class="hljs-params">()</span>{</span><br>            <span class="hljs-keyword">var</span> num = $(<span class="hljs-string">“:text”</span>).val();<br>            <span class="hljs-keyword">return</span> num;<br>        }<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getSelectVal</span><span class="hljs-params">()</span>{</span><br>            <span class="hljs-keyword">var</span> urlPrefix = location.href;  <span class="hljs-comment">//获取页面URL</span><br>            <span class="hljs-comment">//TODO 判断url是否以<em>.html 结尾 是则往下执行</em></span><br>            <span class="hljs-comment">/<br>            if(!urlPrefix.endsWith(“html”)){<br>                return urlPrefix + “index.html”;<br>            }<br>            <em>/</em></span><br>            <span class="hljs-keyword">var</span> substringNum = urlPrefix.lastIndexOf(<span class="hljs-string">“/“</span>); <span class="hljs-comment">//获得最后一个 / 的下标</span><br>            <span class="hljs-keyword">var</span> needPrefix = urlPrefix.substring(<span class="hljs-number">0</span>, substringNum + <span class="hljs-number">1</span>); <span class="hljs-comment">//获取最后一个(包括) / 符号之前的字符串</span><br>            <span class="hljs-keyword">var</span> suffix = $(<span class="hljs-string">“select”</span>).val(); <span class="hljs-comment">//请求页面的路径</span><br>            <span class="hljs-keyword">return</span> needPrefix + suffix;<br>        }<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">load</span><span class="hljs-params">()</span>{</span><br>            <span class="hljs-keyword">var</span> reg = <span class="hljs-keyword">new</span> RegExp(<span class="hljs-string">“^[0-9]$”</span>);<br>            <span class="hljs-keyword">if</span>(!reg.test($(<span class="hljs-string">“:text”</span>).val()) || $(<span class="hljs-string">“:text”</span>).val() == <span class="hljs-number">0</span>){<br>                alert(<span class="hljs-string">“请输入非零正整数查询!”</span>);<br>                $(<span class="hljs-string">“:text”</span>).val(<span class="hljs-string">“500”</span>);<br>                <span class="hljs-keyword">return</span>;<br>            }<br>            $.getJSON(getSelectVal(), <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(data)</span>{</span>  <span class="hljs-comment">//得到Json对象</span><br>                <span class="hljs-keyword">print</span>(getNum(), data);<br>            });<br>        }<br>        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">print</span><span class="hljs-params">(a,obj)</span>{</span><br>            <span class="hljs-comment">//返回查询首页</span><br>            $(<span class="hljs-string">“#messageArea”</span>).html(<span class="hljs-string">“&lt;table align=’center’ border=’1’ cellpadding=’10’ cellspacing=’0’&gt;”</span><br>                    + <span class="hljs-string">“&lt;tr&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“num”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“key”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“total”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“min”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“max”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;th&gt;”</span> + <span class="hljs-string">“average”</span> + <span class="hljs-string">“&lt;/th&gt;”</span><br>                    + <span class="hljs-string">“&lt;/tr&gt;”</span> + <span class="hljs-string">“&lt;/table&gt;”</span>);<br>            <span class="hljs-keyword">var</span> count = <span class="hljs-number">0</span>;<br>            <span class="hljs-keyword">var</span> jVals = obj.result;<br>            <span class="hljs-keyword">for</span>(key in jVals){  <span class="hljs-comment">//输出每个Json对象的信息</span><br>                count++;<br>                $(<span class="hljs-string">“table”</span>).append(<span class="hljs-string">“&lt;tr&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + count + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + key + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].total + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].min + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].max + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;td&gt;”</span> + jVals[key].average + <span class="hljs-string">“&lt;/td&gt;”</span><br>                        + <span class="hljs-string">“&lt;/tr&gt;”</span>);<br>                <span class="hljs-keyword">if</span>(count == a){<br>                    <span class="hljs-keyword">break</span>;<br>                }<br>            }<br>        }<br>    &lt;/script&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;div align=<span class="hljs-string">“center”</span>&gt;&lt;h3&gt;Json输出查询&lt;/h3&gt;&lt;/div&gt;<br>        &lt;div align=<span class="hljs-string">“center”</span>&gt;<br>        &lt;select id=<span class="hljs-string">“selectQuery”</span>&gt;<br>            &lt;option value=<span class="hljs-string">“all.json”</span>&gt;all&lt;/option&gt;<br>            &lt;option value=<span class="hljs-string">“batch.json”</span>&gt;batch&lt;/option&gt;<br>            &lt;option value=<span class="hljs-string">“image.json”</span>&gt;image&lt;/option&gt;<br>        &lt;/select&gt;<br>        请输入查询条数:&lt;input id=<span class="hljs-string">“list”</span> type=<span class="hljs-string">“text”</span> value=<span class="hljs-string">“500”</span>/&gt;<br>        &lt;input type=<span class="hljs-string">“submit”</span> value=<span class="hljs-string">“查询”</span> onclick=<span class="hljs-string">“load()”</span>/&gt;<br>        &lt;/div&gt;&lt;br&gt;&lt;br&gt;<br>        &lt;div id=<span class="hljs-string">“messageArea”</span>&gt;&lt;/div&gt;<br>    &lt;/body&gt;<br>    &lt;/html&gt;<br><br></div>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://hexo.hankchan.cn/2016/04/12/springmvc-e9-80-9a-e8-bf-87-e4-b8-8d-e5-90-8c-e7-9a-84url-e8-bf-94-e5-9b-9ejson-e5-af-b9-e8-b1-a1-e5-b9-b6-e5-9c-a8-e5-89-8d-e7-ab-af-e6-98-be-e7-a4-ba-e7-9a-84-e8-a7-a3-e5-86-b3-e6-96-b9-e6-b3-95/" data-id="cj359k40b001jfwv7uqbptqt5" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    <a class="extend prev" rel="prev" href="/">&laquo; __('prev')</a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><a class="extend next" rel="next" href="/page/3/">__('next') &raquo;</a>
  </nav>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Docker/">Docker</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Eclipse/">Eclipse</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Eclipse/Mybatis/">Mybatis</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Eclipse/Spring/">Spring</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Eclipse/分布式/">分布式</a></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Linux/">Linux</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Linux/Nginx/">Nginx</a></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Mybatis/">Mybatis</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Mybatis/Spring/">Spring</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Mybatis/Spring/SpringMVC/">SpringMVC</a></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Mybatis/SpringMVC/">SpringMVC</a></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Nginx/">Nginx</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Spring/">Spring</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringMVC/">SpringMVC</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/分布式/">分布式</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/日志管理/">日志管理</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/未分类/">未分类</a></li></ul>
    </div>
  </div>


  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">三月 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/01/">一月 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/10/">十月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">九月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/07/">七月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/">五月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">四月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">三月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/02/">二月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">一月 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">十二月 2015</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/03/13/docker-e5-be-ae-e6-9c-8d-e5-8a-a1-e5-ae-b9-e5-99-a8-e5-8c-96-e5-bc-80-e5-8f-91-e6-8e-a2-e7-b4-a2/">Docker-微服务容器化开发探索</a>
          </li>
        
          <li>
            <a href="/2017/01/20/drds-e7-bb-93-e5-90-88mybatis-e8-a7-a3-e5-86-b3-e6-96-b9-e6-a1-88-e4-b8-8e-e8-a7-84-e8-8c-83/">DRDS结合Mybatis解决方案与规范</a>
          </li>
        
          <li>
            <a href="/2017/01/03/springmvc-thymeleaf-e5-bc-80-e5-8f-91-e6-8c-87-e5-8d-97-demo/">SpringMVC-Thymeleaf-开发指南-Demo</a>
          </li>
        
          <li>
            <a href="/2016/10/16/nginx-e4-bb-a3-e7-90-86-e6-9c-8d-e5-8a-a1-e5-99-a8-e6-96-b9-e5-bc-8f-e8-a7-a3-e5-86-b3-e5-ae-9e-e9-99-85-e5-bc-80-e5-8f-91-e4-b8-adajax-e8-af-b7-e6-b1-82-e7-9a-84-e8-b7-a8-e5-9f-9f-e9-97-ae-e9-a2-98/">Nginx代理服务器方式解决实际开发中Ajax请求的跨域问题</a>
          </li>
        
          <li>
            <a href="/2016/10/11/e5-b7-a5-e5-8e-82-e6-a8-a1-e5-bc-8f-e5-92-8c-e5-8d-95-e4-be-8b-e6-a8-a1-e5-bc-8f-e7-bb-93-e5-90-88-e5-ba-94-e7-94-a8-e7-9a-84-e5-9c-ba-e6-99-af-e6-80-9d-e8-80-83/">工厂模式和单例模式结合应用的场景思考</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Hank Chan<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

  </div>
</body>
</html>